我正在尝试使用 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;
}
}
代替:
我会使用:
如果查询参数不适用于此,请尝试:
location @extensionless-php
也应该被删除。其实那是我的错。我看到我的解决方案已经正常工作了。所有查询字符串均已成功传递。