带有SEF URL的Nginx不';t传递GET变量

带有SEF URL的Nginx不';t传递GET变量,nginx,get,request,php,Nginx,Get,Request,Php,我正在运行nginx1.6.1和phpfpm5.5.9。我有一个设置,使SEF网址。请参阅nginx配置的相关部分: location / { # first try if the file or directory exists; if not, redirect to index.php # then index.php will see what to do based on the REQUEST_URI try_files $uri $uri/ /index.p

我正在运行nginx1.6.1和phpfpm5.5.9。我有一个设置,使SEF网址。请参阅nginx配置的相关部分:

location / {
    # first try if the file or directory exists; if not, redirect to index.php
    # then index.php will see what to do based on the REQUEST_URI
    try_files $uri $uri/ /index.php;
}

# and just the basic php-fpm setup...
location ~* \.php$ {
    try_files $uri =404;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    # fastcgi.conf is as distributed, and doesn't contain anything special
    # anyway, the file is shown below
    include fastcgi.conf; 
}
然后,在index.php中:

// Just for testing
var_dump($_SERVER);
var_dump($_GET);
现在,我尝试了一些不同的东西:

My request         REQUEST_URI       GET is passed?
-----------------------------------------------
/index.php?test    /index.php?test   Yes
/index.php/?test   /index.php/?test  No
/?test             /?test            Yes
?test              (redirected to /?test)
/some-dir?test     /some-dir?test    No
/some-dir/?test    /some-dir/?test   No
/index.php/?test
不起作用不是什么大问题。无论如何,最后我们可以使用nginx删除尾部斜杠。但是为什么在最后两种情况下GET变量没有通过呢

当然,我可以使用
parse\uurl
在PHP中处理请求的URI,但是如果我可以使用$\uget访问变量就更好了。怎么了


为完整起见,fastcgi.conf:

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  HTTPS              $https if_not_empty;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

我意外地找到了解决方案:第一个位置块(用于
/
)出现故障。它不应该重写为
/index.php
,而应该重写为
/index.php$is\u args$query\u string

location / {
    try_files $uri $uri/ /index.php$is_args$args;
}
从:

$is_args
-“?”如果请求行有参数,则为空字符串,否则为
$args
-请求行中的参数

现在,为了完整起见,还可以在
服务器
块中使用此重写指令删除尾随斜杠

rewrite ^/(.*)/$ /$1 permanent;

我意外地找到了解决方案:第一个位置块(用于
/
)出现故障。它不应该重写为
/index.php
,而应该重写为
/index.php$is\u args$query\u string

location / {
    try_files $uri $uri/ /index.php$is_args$args;
}
从:

$is_args
-“?”如果请求行有参数,则为空字符串,否则为
$args
-请求行中的参数

现在,为了完整起见,还可以在
服务器
块中使用此重写指令删除尾随斜杠

rewrite ^/(.*)/$ /$1 permanent;

我意外地找到了解决方案:第一个位置块(用于
/
)出现故障。它不应该重写为
/index.php
,而应该重写为
/index.php$is\u args$query\u string

location / {
    try_files $uri $uri/ /index.php$is_args$args;
}
从:

$is_args
-“?”如果请求行有参数,则为空字符串,否则为
$args
-请求行中的参数

现在,为了完整起见,还可以在
服务器
块中使用此重写指令删除尾随斜杠

rewrite ^/(.*)/$ /$1 permanent;

我意外地找到了解决方案:第一个位置块(用于
/
)出现故障。它不应该重写为
/index.php
,而应该重写为
/index.php$is\u args$query\u string

location / {
    try_files $uri $uri/ /index.php$is_args$args;
}
从:

$is_args
-“?”如果请求行有参数,则为空字符串,否则为
$args
-请求行中的参数

现在,为了完整起见,还可以在
服务器
块中使用此重写指令删除尾随斜杠

rewrite ^/(.*)/$ /$1 permanent;