Search code examples
nginxfastcgi

504 Gateway Time-out - upstream timeout


Everything was running smoothly when suddenly my server stopped working. I'm using Linode with Nginx fast-cgi

This is my log file:

upstream timed out (110: Connection timed out) while reading response header from upstream, client: 76.66.174.147, server: iskacanada.com, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.iskacanada.com"

location ~ \.php$ {
    include        fastcgi_params;
    fastcgi_read_timeout 120;
    fastcgi_pass   localhost:9000;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
}

When I want to restart mysql it says:

sudo service mysql restart stop: Unknown instance: start: Job failed to start

Any idea of what is going on?


Solution

  • After a few hours of Debugging here is how I did it:

    Using Ubuntu 12.04, Nginx and php5-fmp

    1. PLease check your log files! log files are your friends. a 504 Gateway problem means that my server is not communicating properly with the website. So In my case I had Nginx and php-fpm that was managing the requests. I had to check 2 log files:

      /var/log/nginx/error.log and /var/log/php5-fpm.log

    in error.log:

    recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 76.66.174.147, server: xxxxxxx.com, request: "GET /wp-admin/ HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.xxxxxxx.com"
    

    in php5-fpm.log:

    unable to bind listening socket for address '127.0.0.1:9000': Address already in use (98)

    So I figured out that I needed to check my php5-fpm process by typing

    netstat | grep 9000
    tcp        0      0 localhost.localdom:9000 localhost.localdo:58424 SYN_RECV   
    tcp      913      0 localhost.localdom:9000 localhost.localdo:57917 CLOSE_WAIT 
    tcp      857      0 localhost.localdom:9000 localhost.localdo:58032 CLOSE_WAIT 
    tcp     1633      0 localhost.localdom:9000 localhost.localdo:58395 CLOSE_WAIT 
    tcp      961      0 localhost.localdom:9000 localhost.localdo:58025 CLOSE_WAIT 
    tcp      857      0 localhost.localdom:9000 localhost.localdo:58040 CLOSE_WAIT 
    tcp      953      0 localhost.localdom:9000 localhost.localdo:58005 CLOSE_WAIT 
    tcp      761      0 localhost.localdom:9000 localhost.localdo:58016 CLOSE_WAIT 
    tcp     1137      0 localhost.localdom:9000 localhost.localdo:57960 CLOSE_WAIT
    

    Lots of close_wait!!! that's abnormal...so I killed all the processes by typing
    fuser -k 9000/tcp

    I then changed my

    /etc/php5/fpm/pool.d/www.conf

    and changing this:

    request_terminate_timeout=30s

    Now the website works. I hope this solved the problem since it was intermittent.