Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

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

            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 -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:, server: localhost, request: "GET /ndex.php HTTP/1.1", upstream: "fastcgi://", host: "localhost"

Please for help.


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

share|improve this question
up vote 2 down vote accepted

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/.

share|improve this answer
I run spawn-fcgi -p 9000 -u www-data -f /usr/bin/php5-cgi spawn-fcgi: child exited with: 2. But when I use commend describe above (netstat) I don't find anything. Can you help me? – Bartosz Kowalczyk May 17 '12 at 6:37
child exited means that it failed to start. Check for log files in /var/log/, and try executing sudo -u www-data /usr/bin/php5-cgi. – mgorven May 17 '12 at 16:57
Ok thank you :) – Bartosz Kowalczyk May 18 '12 at 5:00
How can I open the port if it isn't open? – Adripants Oct 30 '12 at 4:46
@Adripants You seem to be asking a separate question, in which case you should actually ask a question. – mgorven Oct 30 '12 at 6:10

Do you see any errors in the errorlog of your nginx box? (probably somewhere in /var/log/nginx/) This might help when finding the problems.


okay, I missed the part from the logs. What I think is that the config for your fastcgi is incorrect...

share|improve this answer

Your Answer


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.