2017-02-10 4 views
7

Ich habe eine EC2-Instanz, die versucht, eine Rails-App mit Nginx und Unicorn auszuführen.Debugging 502 Fehlerhafter Gateway-Fehler - Ubuntu, Nginx, Unicorn

Ich erhalte einen 502 Bad Gateway Fehler nach etwa 60 Sekunden:

Hier ist, was ich in dem nginx Fehlerprotokoll erhalten:

2017/02/10 18:03:38 [Fehler] 13208 # 13208: * 1 Upstream vorzeitig Verbindung beim Lesen der Response-Header von Upstream, Client: 174.25.146.24, Server: _, Anforderung: "GET/Willkommen HTTP/1.1", Upstream: "http://unix:/home/rails/myapp/shared/sockets/unicorn.sock:/welcome", Host: " mydomain.com "

unicorn.stderr.log

E, [2017-02-13T00: 58: 12,456504 # 13149] ERROR -: Arbeiter = 0 PID: 16535 Timeout (31s> 30s), die Tötung E, [2017-02-13T00: 58: 12.459388 # 13149] FEHLER -: geerntet # worker = 0 Ich, [2017-02-13T00: 58: 12.459499 # 13149] INFO -: worker = 0 laich .. Ich, [2017-02-13T00: 58: 12.461390 # 16810] INFO -: worker = 0 laich pid = 16810 I, [2017-02-13T00: 58: 12.461829 # 16810] INFO -: worker = 0 bereit

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

Berechtigungen auf dem Sockel:

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

Alle Ideen, wie ich kann dies aufspüren ?

+0

Gibt es etwas im Einhornprotokoll? – dimid

+0

Ich habe gerade hinzugefügt, dass in Richtung der Spitze des Beitrags – 99miles

+0

Würden Sie Protokoll von 'unicorn.stdout.log' zur Verfügung stellen können? –

Antwort

2

Ihre Rails-Anwendung sendet keine Antwort an den Unicorn-HTTP-Server innerhalb der durch Ihre Timeout-Einstellungen konfigurierten Zeit (derzeit 30 Sekunden, wie in in Ihrer unicorn.rb konfiguriert).

Entweder erhöhen Sie die timeout Einstellung in Ihrem unicorn.rb, oder (vorzugsweise) debuggen, warum Ihre Rails-Anwendung> 30 Sekunden benötigt, um auf eine Anfrage zu antworten.

Verwandte Themen