【发布时间】:2015-10-14 06:36:50
【问题描述】:
我有一个使用 Puma 在 Nginx 上运行的 Rails 应用程序,就像发条一样,每隔几天应用程序就会出现 502 Bad Gateway 错误。
我的 nginx 日志包含很多这样的错误:
2015/07/23 14:43:49 [error] 14044#0: *7036 connect() to unix:///var/www/myapp/myapp_app.sock failed (111: Connection refused) while connecting to upstream, client: 12.123.12.12, server: myapp.com, request: "GET /arrangements HTTP/1.1", upstream: "http://unix:///var/www/myapp/myapp_app.sock:/arrangements", host: "myapp.com", referrer: "http://myapp.com/arrangements"
我必须重新启动 Puma,然后一切都会再次正常运行......几天。
有什么想法可以解决这个问题吗?我是 nginx 和 puma 的新手。
/etc/nginx/sites-enabled/myapp.com
upstream myapp {
server unix:///var/www/myapp/myapp_app.sock;
}
server {
listen 80;
server_name myapp.com;
root /var/www/myapp/current/public;
client_max_body_size 20M;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
allow all;
satisfy any;
}
location / {
proxy_pass http://myapp; # match the name of upstream directive which is defined above
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ~* ^/assets/ {
# Per RFC2616 - 1 year maximum expiry
expires 1y;
add_header Cache-Control public;
# Some browsers still send conditional-GET requests if there's a
# Last-Modified header or an ETag header even if they haven't
# reached the expiry date sent in the Expires header.
add_header Last-Modified "";
add_header ETag "";
break;
}
}
【问题讨论】:
-
您的应用是否在 Digital Ocean 上运行?
-
您是否收到过来自 DO 的电子邮件?如果没有,我会发布一个。
-
我得到了一些关于升级纽约市一些服务器的信息。这就是我记得的全部。
-
比这更糟糕。我将在答案中发布文本,因为当我尝试将文本发布到此处的 cmets 时,格式完全乱码。
-
当 connect() 返回 ECONNREFUSED 时,表明有问题的套接字由于某种原因未打开,这就是 nginx 返回 502 的原因。也就是说,您的后端 Puma 发生了一些事情。您应该查看您的后端日志以了解它发生了什么。
标签: ruby-on-rails nginx puma