Strange issue with unicorn and nginx caused 502 error

亡梦爱人 提交于 2019-12-12 13:58:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!