Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Messing around with Nginx ... for some reason, it looks like none of my URL parameters are being passed. My homepage loads fine, but a URL like "http://mysite.com/more.php?id=101" throws errors, saying that the ID is an undefined index.

I'm assuming this is something basic I'm missing in a conf file.

Some info: 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;

    }
}

Error log:

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

Thanks in advance.

share|improve this question
    
Post a couple of lines of your /var/www/dev.mysite.com_html/more.php, say lines 8-12 –  Bill Weiss Sep 15 '09 at 21:06

5 Answers 5

I solved a similar issue by appending $args with something like this in your location stanza

try_files $uri $uri/ /www/index.php?$args;
share|improve this answer

To debug this the simplest way it to create a phpinfo.php file in the root directory of your vhost. Call it phpinfo.php and set the content to

<?php phpinfo(); ?>

Then visit http://domain.com/phpinfo.php?id=1, and check the resulting output

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

If this is true then parameters are being passed correctly.

share|improve this answer
    
example.com is a better choice for examples. domain.com is an actual site. –  Ian Mar 5 '13 at 20:21

this my config files:

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;
share|improve this answer

Here's the excerpt from my config file. This works with SugarCRM.

# Catchall for everything else
location / {
  root /var/www/crm.foo.com;
  access_log off;

  index index.php index.html;
  expires 1d;

  try_files $uri $uri/ /index.php?q=$uri;
}

location ~ \.php$ {
  fastcgi_pass   127.0.0.1:9000;
  fastcgi_index  index.php;
  fastcgi_buffer_size 128k;
  fastcgi_buffers 4 256k;
  fastcgi_param  SCRIPT_FILENAME  /var/www/crm.foo.com$fastcgi_script_name;
  include        /usr/local/nginx/conf/fastcgi_params;
}
share|improve this answer

what exactly are you trying to acheive ie use raw php pr some kind of framework, i have cakephp running sucessfully using the following vhost config file

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

 }
}

with the folliwing fastcgi_params file

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;

you should be able to get whatever your thinking of doing running with that subject to more information and your core nginx setup

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.