2

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?

1
  • This question appears to be off-topic because it is aimed at webmasters Commented Oct 16, 2013 at 14:40

3 Answers 3

8

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Very useful, thank you. Other things to do are set listen.backlog to a higher value in fpm conf and also sysctl net.core.somaxconn to a higher value as well.
1

Check if PHP is still running: sudo ps aux | grep php

If it is, restart it sudo service php5-fpm restart if not start it sudo service php5-fpm start.

If you need to restart your database only pass restart, stop or start to the service command: sudo service mysql start or sudo service mysql restart or sudo service mysql stop.

7 Comments

Many thanks :) php5-fpm is restarting well. Now I have a 502 Bad Gateway error!
it now says sudo service mysql restart stop: Unknown instance: start: Job failed to start
Check the error log of your mysql installation. Usually at /var/log/mysql/error.log, you can post the last few lines in your question and let me know so I can help you with that.
Many Thanks Fleshgrinder. The error.log file does not exist. I tried adding it in my my.cnf file but can't restart mysql (service mysql restart stop: Unknown instance: start: Job failed to start )
OK I finally unable the error log for mysql and I got this: 131017 09:47:00 mysqld_safe A mysqld process already exists
|
-1

I just installed winginx and had the 504 gateway problem. The error log pointed at the upstream server "fastcgi://127.0.0.1:9000". This is where nginx proxies to php.

I opened the php-cgi.conf and found that php was listening on port 9054. Changed the port to 9000 and all is well.

Gateway is the route and/or port that nginx uses to connect to a service. For instance, Mongodb is configured to listen on port 27017 out of the box. For security reasons, I tend to change the default ports on services such as php etc. on production servers.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.