我正在尝试使用 Nginx 运行 PHP 应用程序。重写 URL 可以正常工作,但是查询字符串不会传递给 PHP 文件。我在以下配置中做错了什么吗?如果能得到任何帮助,我将不胜感激!
nginx-site.conf:
server {
root /var/www/html;
include /etc/nginx/default.d/.conf;
index index.php index.html index.htm;
client_max_body_size 30m;
server_tokens off;
location / {
index index.html index.htm index.php;
try_files $uri $uri/ @extensionless-php;
}
location ~* .(?:ico|css|js|gif|jpe?g|png|svg|woff)$ {
expires 30d;
add_header Pragma public;
add_header Cache-Control "public";
}
location ~ \.php$ {
fastcgi_param HTTP_PROXY "";
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
location @extensionless-php {
if ( -f $document_root$uri.php ) {
rewrite ^ $uri.php last;
}
fastcgi_pass 127.0.0.1:9000;
include fastcgi.conf;
}
location ~* /includes/(.+)\.php$ {
deny all;
}
}
答案1
代替:
location / {
index index.html index.htm index.php;
try_files $uri $uri/ @extensionless-php;
}
我会用:
location / {
index index.html index.htm index.php;
try_files $uri $uri.php =404;
}
如果查询参数不适用于此,请尝试:
try_files $uri $uri.php$is_args$args =404;
也应location @extensionless-php
被删除。
答案2
其实那是我的错误。我发现我的解决方案已经正常工作了。所有查询字符串都已成功传递。