2

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.

3

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

4
  • I run spawn-fcgi 127.0.0.1 -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
  • 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
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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