间歇性502网关错误,Nginx / Passenger / Rails

时间:2016-11-21 20:45:04

标签: ruby-on-rails-4 nginx ubuntu-14.04 passenger development-environment

我一直在试着弄清楚自第1天以来似乎一直在发生的这些间歇性的502错误。

这通常似乎只发生在开发环境中,我认为这是因为我有相当多的资产被加载。

这是浏览器中的错误,(请记住,它始终是一个不同的文件,可以获得502错误,它可以是css或js,有时没有文件得到502错误)

GET https://example.com/assets/asset.self-368aecefa09656a2be5c72dc8e685b120363a3df812134cbd2dd998bafa179fd.js?body=1 502

在nginx错误日志中显示此

[ 2016-11-21 13:17:43.2054 17184/7efd3bfff700 age/Cor/Con/InternalUtils.cpp:112 ]: [Client 2-66] Sending 502 response: application did not send a complete response
[ 2016-11-21 13:17:43.2112 17184/7efd3bfff700 age/Cor/CoreMain.cpp:819 ]: Checking whether to disconnect long-running connections for process 17411, application /home/user/app/public (development)

在rails development.log中显示<​​/ p>

Started GET "/assets/asset.self-368aecefa09656a2be5c72dc8e685b120363a3df812134cbd2dd998bafa179fd.js?body=1" for 64.72.213.76 at 2016-11-21 13:24:24 -0700
Started GET "/assets/profile.self-c0665056b47c3ab674073339b59398e0dd63f2b5080c9418e2401dee223f31c6.css?body=1" for 64.72.213.76 at 2016-11-21 13:24:25 -0700
Started GET "/assets/ratings.self-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.css?body=1" for 64.72.213.76 at 2016-11-21 13:24:25 -0700

这是我的nginx.conf

user  user user;
worker_processes  1;
error_log  /var/log/nginx/error.log;
pid        /run/nginx.pid;
events {
    worker_connections  2048;
}
http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  /var/log/nginx/access.log  main;
    sendfile        on;
    keepalive_timeout  65;
    gzip  on;
    index   index.html index.htm;
    server {
        listen              443 ssl;
        server_name         example.com;
        ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers         HIGH:!aNULL:!MD5;
        root /home/user/app/public;

        location / {
          passenger_enabled on;
          passenger_ruby /usr/bin/ruby;
          passenger_buffers 16 32k;
          passenger_buffer_size 64k;
          passenger_intercept_errors on;
          passenger_app_env development;
          auth_basic "Restricted Content";
          auth_basic_user_file /etc/nginx/.htpasswd;
        }
    }
    client_max_body_size 20M;

    fastcgi_buffers 16 32k;
    fastcgi_buffer_size 64k;
    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    proxy_buffers 8 16k;
    proxy_buffer_size 32k;
    server {
        root         /usr/share/nginx/html;
        include /etc/nginx/default.d/*.conf;

        location / {
        }
        error_page  404              /404.html;
        location = /40x.html {
        }
        location = /50x.html {
        }
    }
}

1 个答案:

答案 0 :(得分:0)

我只需要禁用一些导致延迟的宝石

在我的Gemfile中评论了这些行:

#gem 'figaro'
#gem 'therubyracer'
#gem 'cocaine'
#gem 'pry'
#gem 'pry-doc'
#gem 'roadie'
#gem 'public_activity'
#gem 'stackprof'
#gem 'activerecord-reputation-system'
#gem 'rails-perftest'
#gem 'ruby-prof'