只有当.php被添加参数时,Nginx才会将.PHP作为下载文件

这是我目前的nginxconfiguration:

server { server_name mydomain.example; access_log /srv/www/mydomain.example/logs/access.log; error_log /srv/www/mydomain.example/logs/error.log; root /srv/www/mydomain.example/public_html; error_page 404 /404; location / { if ($request_uri ~ ^(.*)\.(php|html)$) { return 302 $1$is_args$args; } try_files $uri $uri/index.html $uri/index.htm @php; index index.html index.htm index.php; } location @php { include /etc/nginx/fastcgi_params; fastcgi_pass unix:/var/run/php-fpm/www.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; try_files $uri.php $uri/index.php =404; } location /support { rewrite ^(.*)\.php$ $1 break; try_files $uri $uri/index.html $uri/index.htm @php; } location /blog { rewrite ^(.*)\.php$ $1 break; try_files $uri $uri/index.html $uri/index.htm @php; } } 

所以基本上我有一个巨大的安全问题,需要尽快解决。 当我去“mydomain.example /文件名?arg = 7887”一切工作正常。 但是,当一个客户端试图去“mydomain.example / filename.php?arg = 7887”服务器决定将该文件作为下载服务。 我需要去掉.php文件,并将其重写为“mydomain.example / filename?arg = 7887”。 它似乎只发生在.php后面的参数时,否则它会剥离.php并正常工作。

这是因为try_files疯狂和其他可疑的方法。 删除所有的练习,并使其规范:

location / { index index.html; if (!-e $request_filename) { rewrite ^/(.*)$ /index.php; } }

location ~ \.php$ { include /etc/nginx/fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param QUERY_STRING $query_string; fastcgi_pass 127.0.0.1:9000; fastcgi_intercept_errors on; fastcgi_cache default; break; }