大网数据广告活动
服务器运维问答

Nginx & PHP-FPM: Query parameters won't be passed to PHP

· 52CE 我爱测

I am currently setting up a machine for local development using Vagrant. Everything runs as it should, expect query parameters aren't passed to PHP on subpages. That means on www.example.com/?a=b , the query parameter is accessib…

问题原文

原帖链接 · Sven · CC BY-SA 3.0

I am currently setting up a machine for local development using Vagrant. Everything runs as it should, expect query parameters aren't passed to PHP on subpages.

That means on www.example.com/?a=b, the query parameter is accessible, but on www.example.com/subpage/?a=b it's not.

The general reply I found using Google for this problem is to modify the try_files directive, but that isn't working for me. I've also checked the request_order & variables_order in php.ini – everything is setup correctly there.

This is my config:

 server {
     listen                80;
     server_name           example.com www.example.com;
     root                  /var/www/public;

     location / {
         index   index.html index.htm index.php;
         try_files $uri $uri/ /index.php?$query_string;
         include /etc/nginx/fastcgi_params;
     }

     location ~ \.php$ {
         fastcgi_pass 127.0.0.1:9000;
         fastcgi_index index.php;
         fastcgi_param SCRIPT_FILENAME $request_filename;
         include /etc/nginx/fastcgi_params;
     }

     sendfile off;
}

Since I don't know much about server setup & administration, I am hitting a brick wall here, still here are a few things I also checked:

  • $query_string is set in /etc/nginx/fastcgi_params as fastcgi_param QUERY_STRING $query_string; which seems correct to me.
  • The path to fastcgi_params is correct

Since it works when not being on a subpage, I am now suspecting the location blocks not matching, but I really don't understand how this could be the case – please help.

社区高分解答

原帖链接 · risyasin · CC BY-SA 3.0

You need to use $is_args for question mark & $args or $query_string for query string afterwards question mark.

here it's the last combination.

try_files $uri $uri/ /index.php$is_args$query_string;

Also be sure that you have set

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_split_path_info ^(.+\.php)(/.+)$;

then pass it fastcgi;

fastcgi_pass 127.0.0.1:9000;

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2015-04-25)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。