1

お客様に API を提供する CGI スクリプトがあります。呼び出し構文は次のとおりです。

script.cgi?module=<str>&func=<str>[&other-options]

タスクは、異なるモジュールに対して異なる認証ルールを作成することです。

必要に応じて、適切な URL があると便利です。

私の設定:

<VirtualHost *:80>
    DocumentRoot /var/www/example
    ServerName example.com

    # Global policy is to deny all
    <Location />
            Order deny,allow
            Deny from all
    </Location>


    # doesn't work :(
    <Location /api/foo>
            Order deny,allow
            Deny from all
            Allow from 127.0.0.1
    </Location>


    RewriteEngine On

    # The only allowed type of requests:
    RewriteRule /api/(.+?)/(.+) /cgi-bin/api.cgi?module=$1&func=$2 [PT]

    # All others are forbidden:
    RewriteRule /(.*) - [F]

    RewriteLog /var/log/apache2/rewrite.log
    RewriteLogLevel 5

    ScriptAlias /cgi-bin /var/www/example

    <Directory /var/www/example>
            Options -Indexes
            AddHandler cgi-script .cgi
    </Directory>

 </VirtualHost>

問題は、そのディレクティブを処理する順序であることはわかっています。<Location>s は、mod_rewrite が作業を完了した後に処理されます。でも、変える方法はあると思います。:)

このような他の場所で一般的に使用されるため、標準のOrder deny,allow+Allow from <something>ディレクティブを使用することをお勧めします。

ご清聴ありがとうございました。:)

4

0 に答える 0