问题
We have Ruby on Rails application, that is running on VPS. This night the nginx went down and responded with "502 Bad Gateway". Nginx error log contained lots of folowing messages:
2013/10/02 00:01:47 [error] 1136#0: *1 connect() to
unix:/app_directory/shared/sockets/unicorn.sock failed (111: Connection refused) while
connecting to upstream, client: 5.10.83.46, server: www.website.com, request: "GET /resource/206 HTTP/1.1", upstream: "http://unix:/app_directory/shared/sockets/unicorn.sock:/resource/206", host: "www.website.com"
These errors started suddenly, because previous error messages was 5 days earlier.
So the problem was in unicorn server. Then i opened unicorn error log and found there just some info messages, which doesn't connected with a problem. Production log was useless too.
I tried to restart server via service nginx restart
, but it didn't help. Also there were not some pending processes of unicorn.
The problem was solved when i redeploy the application. And it is strange, because i deployed the same version of application 10 hours before server went down.
I'm looking for any suggestions how to prevent such 'magic' cases in future. Appreciate any help you can provide!
回答1:
Looks like your unicorn server wasn't running when nginx tried to access it.
This can be caused by VPS restart, some exception in unicorn process, or killing of unicorn process due to low free memory. (IMHO VPS restart is the most possible reason) Check unicorn by
ps aux | grep unicorn
Also you can check server uptime with
uptime
Then you can:
- add script that would start unicorn on VPS boot
- add it as service
- run some monitoring process (like monit)
来源:https://stackoverflow.com/questions/19133060/strange-issue-with-unicorn-and-nginx-caused-502-error