Nginx: 502 Bad GateWay

502-errorconfigurationnginx

I try install nginx. I used to lighttpd but now we must install nginx.
Can you help me with configuration nginx?

I use debian 6.
My nginx.conf:

user www-data;
worker_processes 4;
pid /var/run/nginx.pid;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

My site-enable/default look as

server {
    listen   80; ## listen for ipv4; this line is default and implied
    #listen   [::]:80 default ipv6only=on; ## listen for ipv6

    root /var/www; #!
    index index.php index.html index.htm; #1
    access_log      /var/log/nginx/access.log info;
    error_log       /var/log/nginx/error.log info;

    # Make site accessible from http://localhost/
    server_name localhost;

    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to index.html
            autoindex on;
            # Uncomment to enable naxsi on this location
            # include /etc/nginx/naxsi.rules
    }

    location /doc/ {
            alias /usr/share/doc/;
            autoindex on;
            allow 127.0.0.1;
            deny all;
    }

    location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            include fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one

    location ~ /\.ht {
            deny all;
    }
}

I add to php.ini

cgi.fix_pathinfo = 0;     

    

php5-cgi is running as

spawn-fcgi 127.0.0.1 -p 9000 -u www-data -f /usr/bin/php5-cgi

But I get 502 error (bad gateway)
My /var/log/ say

2012/05/16 15:35:25 [error] 13427#0: *12 connect() failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET /ndex.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "localhost"

I didn't run sqpwn-fcgi => php-cgi isn't listening on port 9000.

Best Answer

PHP either isn't running, or is running but not listening on that socket. Check that it's running with ps -eF | grep php, and that it's listening with netstat -tlpn | grep :9000. Check for error messages from PHP in either /var/log/syslog or it's own log file in /var/log/.