2017-02-10 2 views
7

J'ai une instance EC2, en essayant d'exécuter une application Rails avec Nginx et Unicorn.Débogage 502 erreur Bad Gateway - Ubuntu, Nginx, Unicorn

Je continue à obtenir une erreur 502 Passerelle incorrecte après environ 60 secondes:

Voici ce que je reçois l'erreur nginx journal:

2017/02/10 18:03:38 [error] 13208 # 13208: * 1 en amont prématurément fermé la connexion en lisant l'en-tête de réponse en amont, client: 174.25.146.24, serveur: _, requête: "GET/welcome HTTP/1.1", en amont: "http://unix:/home/rails/myapp/shared/sockets/unicorn.sock:/welcome", hôte: " mydomain.com "

unicorn.stderr.log

E, [2017-02-13T00: 58: 12,456504 # 13149] ERREUR -: travailleur = 0 PID: 16535 délai d'attente (31s> 30 ans), tuant E, [2017-02-13T00: 58: 12.459388 # 13149] ERREUR:: moissonné # worker = 0 I, [2017-02-13T00: 58: 12.459499 # 13149] INFO -: worker = 0 spawning .. I, [2017-02-13T00: 58: 12.461390 # 16810] INFO -: travailleur = 0 engendré pid = 16810 I, [2017-02-13T00: 58: 12.461829 # 16810] INFO -: worker = 0 prêt

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' 

sites disponibles/default

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; 
} 

autorisations sur la prise:

srwxrwxrwx 1 rails rails 0 Feb 10 18:00 unicorn.sock 

Toutes les idées sur la façon dont je peut suivre cela ?

+0

Y a-t-il quelque chose dans le journal de la licorne? – dimid

+0

Je viens d'ajouter que vers le haut de la poste – 99miles

+0

Seriez-vous en mesure de fournir le journal de «unicorn.stdout.log»? –

Répondre

2

Votre application Rails ne renvoie pas de réponse au serveur HTTP Unicorn dans le délai configuré par vos paramètres de délai (actuellement 30 secondes, comme configuré par la ligne timeout 30 dans votre unicorn.rb). Augmentez le paramètre timeout dans votre unicorn.rb, ou (de préférence) déboguez pourquoi votre application Rails prend plus de 30 secondes pour répondre à une demande.