Nginx 未传递 URL 参数

Nginx 未传递 URL 参数

摆弄 Nginx ... 出于某种原因,似乎我的 URL 参数都没有被传递。我的主页加载正常,但像“http://mysite.com/more.php?id=101“抛出错误,说该 ID 是未定义的索引。

我认为这是我在配置文件中缺少的一些基本内容。

一些信息:conf.d/virtual.conf

server {
    listen       80;
    server_name  dev.mysite.com;
    index   index.php;
    root   /var/www/dev.mysite.com_html;

    location / {
    root /var/www/dev.mysite.com_html;
    }
    location ~ \.php(.*)$  {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_param SCRIPT_FILENAME /var/www/wap/dev.mysite.com_html/$fastcgi_script_n
ame;
    fastcgi_index index.php;
include /etc/nginx/fastcgi_params;

    }
}

错误日志:

2009/06/22 11:44:21 [notice] 16319#0: start worker process 16322
2009/06/22 11:44:28 [error] 16320#0: *1 FastCGI sent in stderr: "PHP Notice:  Undefined index:  id in /var/www/dev.mysite.com_html/more.php on line 10

提前致谢。

答案1

我通过在你的节中添加$args类似这样的内容解决了类似的问题location

try_files $uri $uri/ /www/index.php?$args;

答案2

phpinfo.php要调试此问题,最简单的方法是在 vhost 的根目录中创建一个文件。调用它phpinfo.php并将内容设置为

<?php phpinfo(); ?>

然后访问http://domain.com/phpinfo.php?id=1,并检查结果输出

_ENV["REQUEST_URI"] /mail/phpinfo.php?id=1

如果这是真的那么参数传递就是正确的。

答案3

这是我的配置文件:

location ~ .*.php$ {
   include /etc/nginx/fastcgi_params;
   fastcgi_pass    127.0.0.1:1026;                         
   #spawn-fcgi -u nobody -a 127.0.0.1 -p 1026 -f /usr/bin/php-cgi
   fastcgi_index   index.php;                            

   fastcgi_param   SCRIPT_FILENAME /var/www//htdocs/$fastcgi_script_name;
}



#/etc/nginx/fastcgi_params

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  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;

答案4

你到底想实现什么,即使用原始 php 或某种框架,我使用以下 vhost 配置文件成功运行 cakephp

server {

            listen   80;
            server_name  www.domain.com;
            rewrite ^/(.*) http://domain.com/$1 permanent;

           }

server {

            listen   80;
            server_name  domain.com;

            access_log /home/public_html/domain.com/log/access.log;
            error_log /home/public_html/domain.com/log/error.log;

                location / {

                        root /home/public_html/domain.com/app/webroot;
                        index index.php;

                        if (-f $request_filename) {
                        break;
                        }
                        if (!-f $request_filename) {
                        rewrite ^/(.+)$ /index.php?url=$1 last;
                        break;
                        }


         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        location ~ .php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME /home/public_html/domain.com/app/webroot/index.php;
           #$fastcgi_script_name;
            include        /etc/nginx/fastcgi_params;
        }

 }
}

使用以下 fastcgi_params 文件

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  SCRIPT_NAME        $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  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx;

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;
fastcgi_param  REDIRECT_STATUS    200;

你应该能够获得有关该主题的更多信息和核心 nginx 设置,无论你打算做什么

相关内容