PHP子路径的NGINX位置块

时间:2018-02-15 16:31:15

标签: php nginx nginx-location

我正在尝试过滤路径以专门执行以下操作(按此顺序我认为):

  1. 允许来自世界各地的所有流量到路径/PROD/index.php?/report(以及之后的任何内容/报告,如下面的示例)并阻止流量到其他任何地方
    • 允许:/PROD/index.php?/ report
    • 允许:/PROD/index.php?/report /
    • 允许:/PROD/index.php?/report/werwf
    • DENY:/PROD/index.php?/{anything else}
  2. 允许来自我们拥有的范围内任何IP地址的所有流量(由x.x.x.x / 16表示)
  3. 我目前的NGINX配置是:

    server {
        listen 443 http2 ssl;
    
        error_page 404 /404.html;
        error_page 500 502 503 504 /50x.html;
    
        ssl_certificate /etc/nginx/ssl/fsmunkireport.stockton.edu.cer;
        ssl_certificate_key /etc/nginx/ssl/fsmunkireport.stockton.edu.key;
        #ssl_dhparam /etc/nginx/ssl/dhparam.pem;
    
        location = / {
          return 301 https://fqdn/PROD/index.php?;
        }
    
        location ~ ^\/PROD\/index.php\?\/report(.*) {
          allow all;
          index index.php;
          autoindex on;
          location ~* \.php$ {
              try_files $uri =404;
              fastcgi_index index.php;
              fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
              fastcgi_param SCRIPT_FILENAME  /secure/PPRD/$fastcgi_script_name;
              include fastcgi_params;
              include fastcgi.conf;
          }
        }
    
        location /PROD {
          allow x.x.x.x/16;
          deny all;
          index index.php;
          autoindex on;
          location ~* \.php$ {
              try_files $uri =404;
              fastcgi_index index.php;
              fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
              fastcgi_param SCRIPT_FILENAME  /secure/PPRD/$fastcgi_script_name;
              include fastcgi_params;
              include fastcgi.conf;
          }
        }
    }
    

    我遇到的问题是通过该php子路径进行过滤。由于它不是文字目录,我想我只是在混淆自己。基本上在这一点上,所有流量都是通过NGINX允许的,这不是理想的行为。

    非常感谢任何协助。

0 个答案:

没有答案