Nginx
php-fpm 和 nginx 的查詢字元串問題
我正在嘗試使用 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 / { 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
也應該被刪除。