2016-05-18 8 views
0

を除外:ここに興味のnginxの場所ブロック - 私は、クライアント・サーバ・クラスタ上のサイトのために、次のnginxのサーバーのブロックを持っている特定のPHPファイル

# Create shared memory zone for managing requests from IP's. Request rate set at 60 requests per minute, equates to 1 per second. 
# Any quicker than this and nginx will serve 404, instead of the resource. 
limit_req_zone $binary_remote_addr zone=xmlrpc:10m rate=60r/m; 

# Create shared memory zone for managing active connections. Works almost the same as above. Not currently using this. 
limit_conn_zone $binary_remote_addr zone=addr:10m; 

    server { 
     listen  80 default_server; 
     listen  [::]:80 default_server; 
     server_name REMOVED; 
     root   /var/www/REMOVED/html; 
     client_max_body_size 20M; 

     # Load configuration files for the default server block. 
     include /etc/nginx/default.d/ *.conf; 

     location/{ 
     #root   /var/www/REMOVED/html; 
     index index.php index.htm index.html; 
     proxy_read_timeout 200; 
     #try_files $uri $uri/ =404; 
     try_files $uri $uri/ /index.php?$args; 
     include /var/www/REMOVED/html/nginx.conf; 
     } 

     location /xmlrpc.php { 
     limit_req zone=xmlrpc; 
     #limit_conn addr 10;#DO NOT USE 
     } 

     # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 
     location ~ \.php$ { 
       root   /var/www/REMOVED/html; 
       fastcgi_pass 127.0.0.1:9000; 
       fastcgi_index index.php; 
       fastcgi_read_timeout 200; 
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
       include  fastcgi_params; 
     } 

     location ~ ^/(status|ping)$ { 
     access_log off; 
     allow 127.0.0.1; 
     allow 10.10.10.0/24; 
     allow 10.10.33.11; 
     deny all; 
     include fastcgi_params; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     fastcgi_pass 127.0.0.1:9000; 
     } 

     error_page 404 /404.html; 
      location = /404.html { 
     } 

     error_page 500 /500.html; 
      location = /500.html { 
     } 
    } 

面積は私が制限しようとしていますトップ数行です単一のリソースに対する単一の所与のIPアドレスに対する所与の時間枠内の要求の数。具体的には、私はワードプレスインストールで1秒あたりのリクエスト数を1 IPからxmlrpc.phpに制限しようとしています。

テスト用のhtmファイルを作成し、xmlrpc.phpからtestfile.htmにロケーションブロックを変更すると、これはすべて意図どおりに動作し、1秒あたり1回より多くのリクエストがブロックされ、ブロックされ、代わりに404にヒットします。しかし、私が場所ブロックxmlrpc.phpを作った場合、それは動作しません、私はまだ私が望むすべてのdomain.com/xmlrpc.phpを押すことができ、私は決してブロックされていません。

すべてのPHPリクエストを処理するためにphp-fpmを使用していますが、NginxはPHPファイルのプロキシとしてしか動作しません。 location ~ \.php$ {ロケーションブロックはそれを処理します。

私の現在の理論は、xmlrpc.php要求はNginxによって直接処理されずに処理されないため、Nginx内で設定された要求制限を無視しているということです。

私はメインlocation ~ \.php$ {場所からつまりxmlrpc.phpを除外することができます方法はありますので、それらは要求の制限によって影響されますが、つまりxmlrpc.phpファイルがまだ合法的な方法でアクセスするとき意図したとおりに動作しますか?ありがとう。

答えて

0

解決済み。問題は、nginxがロケーションブロックを処理し続け、すべての.phpファイルをキャッチすることを使用したことでした。オリジナルのxmlrpc.phpを無視します。

"="演算子を使用して/xmlrpc.phpとの完全一致を検索しました。そのため、nginxは、それが一致した後にさらに多くの場所ブロックの処理を停止します。

これは、テストおよび検証されています
location = /xmlrpc.php { 
    limit_req zone=xmlrpc; 
    #limit_conn addr 10;#DO NOT USE 
      root   /var/www/REMOVED/html; 
      fastcgi_pass 127.0.0.1:9000; 
      fastcgi_index index.php; 
      fastcgi_read_timeout 200; 
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
      include  fastcgi_params; 
    } 

は、正常に動作します:

私の最終的な位置ブロックはこのように見てしまいました。ありがとう。

関連する問題