独角兽和Nginx的奇怪问题导致502错误 [英] Strange issue with unicorn and nginx caused 502 error

查看:116
本文介绍了独角兽和Nginx的奇怪问题导致502错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有在VPS上运行的Ruby on Rails应用程序.今晚,nginx崩溃了,并回答"502 Bad Gateway". Nginx错误日志包含许多以下消息:

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"

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"

这些错误突然开始,因为以前的错误消息早于5天.

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.

我尝试通过 service nginx restart 重新启动服务器,但没有帮助.也没有独角兽的一些悬而未决的过程.

I tried to restart server via service nginx restart, but it didn't help. Also there were not some pending processes of unicorn.

当我重新部署该应用程序时,该问题已解决.而且很奇怪,因为我在服务器宕机10个小时之前就部署了相同版本的应用程序.

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!

推荐答案

当nginx尝试访问它时,好像您的独角兽服务器未运行.

Looks like your unicorn server wasn't running when nginx tried to access it.

这可能是由于VPS重新启动,独角兽进程中的某些异常或由于可用内存不足而导致的独角兽进程终止而引起的. (IMHO VPS重新启动是最可能的原因) 通过

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

然后您可以:

  • 添加将在VPS启动时启动独角兽的脚本
  • 将其添加为服务
  • 运行一些监视过程(例如监视)

这篇关于独角兽和Nginx的奇怪问题导致502错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆