我有一個EC2實例,試圖用Nginx和Unicorn運行Rails應用程序。調試502錯誤的網關錯誤 - Ubuntu,Nginx,Unicorn
我一直在約60秒後,得到一個502錯誤網關錯誤:
這裏就是我的nginx的錯誤日誌中獲得:
2017年2月10日18時03分38秒[錯誤] 13208#13208:* 1上游過早 在讀取來自上游的響應頭時關閉連接,客戶端: 174.25.146.24,服務器:_,請求:「GET/welcome HTTP/1.1」,上游:「http://unix:/home/rails/myapp/shared/sockets/unicorn.sock:/welcome」, 主機: mydomain.com「
unicorn.stderr.log
E,[2017-02-13T00:58:12.456504#13149]錯誤 - :工人= 0 PID:16535 超時(31S> 30秒),殺E, [2017-02-13T00:58:12.459388#13149] 錯誤 - :收割# worker = 0我,[2017-02-13T00:58:12.459499#13149]信息 - :worker = 0 產卵..我,[2017-02-13T00:58:12.461390#16810]信息 - :工人= 0 派生pid = 16810我,[2017-02-13T00:58:12.461829#16810]信息 - : 工人= 0準備好
nginx.conf
user rails;
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 1024;
# 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;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# 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/javascript text/xml application/xml application/xml+rss text/javascript;
# upstream unicorn {
# server unix:/home/rails/myapp/shared/sockets/unicorn.sock fail_timeout=0;
# }
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
unicorn.rb
# set path to application
app_dir = File.expand_path("../..", __FILE__)
shared_dir = "#{app_dir}"
working_directory app_dir
print shared_dir
# Set unicorn options
worker_processes 2
preload_app true
timeout 30
print '1'
# Set up socket location
listen "#{shared_dir}/shared/sockets/unicorn.sock", :backlog => 64
print '2'
# Logging
stderr_path "#{shared_dir}/shared/log/unicorn.stderr.log"
stdout_path "#{shared_dir}/shared/log/unicorn.stdout.log"
print '3'
# Set master PID location
pid "#{shared_dir}/shared/pids/unicorn.pid"
print '4'
網站可用/默認
upstream app {
# Path to Unicorn SOCK file, as defined previously
server unix:/home/rails/myapp/shared/sockets/unicorn.sock fail_timeout=0;
}
server {
listen 80;
server_name _;
root /home/rails/myapp/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;
}
權限在插座上:
srwxrwxrwx 1 rails rails 0 Feb 10 18:00 unicorn.sock
如何我的任何想法可以追蹤這一點?
獨角獸的日誌裏有什麼嗎? – dimid
我剛剛在帖子的頂部添加了 – 99miles
你能提供'unicorn.stdout.log'的日誌嗎? –