[英]Rails 5 app with Puma and Nginx - 111: Connection refused while connecting to upstream, client
我收到這個錯誤:
2016/09/29 01:05:39 [error] 7169#0: *3 connect() to unix:/home/deploy/tasks/shared/tmp/sockets/puma.sock failed (111: Connection refused) while connecting to upstream, client: 99.254.197.158, server: localhost, request: "GET / HTTP/1.1", upstream: "http://unix:/home/deploy/tasks/shared/tmp/sockets/puma.sock:/", host: "ec2-54-88-181-57.compute-1.amazonaws.com"
嘗試將此網址用於我的應用時:
http://ec2-54-88-181-57.compute-1.amazonaws.com/
瀏覽器還會顯示以下消息:
We're sorry, but something went wrong.
If you are the application owner check the logs for more information.
但是,當使用此URL直接在端口3000上使用Puma時,我可以訪問我的應用程序:
http://ec2-54-88-181-57.compute-1.amazonaws.com:3000/
我可以通過這種方式瀏覽應用程序的所有頁面。
以下是我的一些配置文件:
$ ls -l /etc/nginx/sites-enabled
total 0
lrwxrwxrwx 1 root root 34 Sep 28 22:46 default -> /etc/nginx/sites-available/default
$ sudo cat /etc/nginx/nginx.conf
[sudo] password for deploy:
user root; #www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
##
# nginx-naxsi config
##
# Uncomment it if you installed nginx-naxsi
##
#include /etc/nginx/naxsi_core.rules;
##
# nginx-passenger config
##
# Uncomment it if you installed nginx-passenger
##
#passenger_root /usr;
#passenger_ruby /usr/bin/ruby;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
$ sudo cat /etc/nginx/sites-available/default
upstream app {
# Path to Puma SOCK file, as defined previously
server unix:/home/deploy/tasks/shared/tmp/sockets/puma.sock fail_timeout=0;
}
server {
listen 80;
server_name localhost;
root /home/deploy/tasks/current/public;
try_files $uri/index.html $uri @app;
location @app {
proxy_pass http://app;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
服務器正在偵聽端口80,22和3000(對於Puma)
$ netstat -an
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:3000 0.0.0.0:* LISTEN
tcp 0 280 172.31.51.143:22 99.254.197.158:60843 ESTABLISHED
tcp 0 0 172.31.51.143:22 99.254.197.158:60842 ESTABLISHED
tcp 0 0 172.31.51.143:59545 172.31.47.0:5432 ESTABLISHED
tcp 0 0 172.31.51.143:59544 172.31.47.0:5432 ESTABLISHED
tcp6 0 0 :::22 :::* LISTEN
udp 0 0 0.0.0.0:55159 0.0.0.0:*
udp 0 0 0.0.0.0:68 0.0.0.0:*
udp6 0 0 :::12784 :::*
Nginx和Puma正在運行。
$ ps -ef | grep nginx
root 1644 1586 0 01:21 pts/0 00:00:00 sudo tail -f /var/log/nginx/error.log
root 1645 1644 0 01:21 pts/0 00:00:00 tail -f /var/log/nginx/error.log
root 1698 1 0 01:39 ? 00:00:00 nginx: master process /usr/sbin/nginx
root 1701 1698 0 01:39 ? 00:00:00 nginx: worker process
root 1702 1698 0 01:39 ? 00:00:00 nginx: worker process
root 1703 1698 0 01:39 ? 00:00:00 nginx: worker process
root 1704 1698 0 01:39 ? 00:00:00 nginx: worker process
deploy 1736 1309 0 02:13 pts/1 00:00:00 grep nginx
$ ps -ef | grep puma
deploy 1564 1 0 01:20 ? 00:00:00 puma 3.6.0 (tcp://0.0.0.0:3000) [20160928212850]
deploy 1571 1564 0 01:20 ? 00:00:01 puma: cluster worker 0: 1564 [20160928212850]
我正在使用Capistrano部署到AWS EC2 Ubuntu 14.04服務器。 沒有與部署相關的錯誤。
我找到了我發現的所有博客/帖子但到目前為止這些解決方案都沒有對我有用。
為了讓Nginx服務器正常工作,接下來我會嘗試什么?
我廢棄了AWS EC2實例並使用Ubuntu 14.04實現重新創建它,我將其升級到16.04。 我嚴格遵循這里的指導
http://codepany.com/blog/rails-5-puma-capistrano-nginx-jungle-upstart/以及來自同一博客的相關鏈接。
現在Nginx和Puma正在一起工作,我的應用程序運行完美:
http://ec2-54-159-156-217.compute-1.amazonaws.com/指南的唯一區別是我保留了數據庫的AWS RDS實例。 雖然我在Mac上使用RBENV,但我在生產服務器中使用了RVM。 我使用ubuntu用戶(比如root)進行部署,因為我懷疑我遇到的所有麻煩都與權限相關,我不知道如何修復它們。
之前遇到的許多錯誤試圖在套接字上正確啟動Puma並使其與Nginx一起使用,尤其是在之后不重啟
cap生產部署與生成秘密並將此值放在適當的文件中有關。 對我來說,它最好在/ etc / environment文件中編寫它。
我還對文件/ etc / ssh / sshd_config進行了更改,以便通過ssh獲取root或ubuntu訪問權限。 在這件事這個鏈接
https://forums.aws.amazon.com/thread.jspa?threadID=86876非常有用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.