【问题标题】:Nginx, Unicorn and Rails = 502 Bad GatewayNginx、Unicorn 和 Rails = 502 错误网关
【发布时间】:2015-05-21 21:43:35
【问题描述】:

我正在尝试设置 Nginx、Unicorn 和 Rails 应用程序一起工作。 Nginx 和 Nnicorn 正在运行,我使用 ps 命令检查过。

但是当我试图访问我的页面时,我得到了 502 Bad Gateway

Nginx 错误日志有一行:

2015/03/18 19:53:26 [错误] 14319#0: *1 connect() to unix:/var/sockets/unicorn.mypage.sock 失败(11:资源暂时 不可用)同时连接到上游

可能是什么问题?

我的 /etc/nginx/conf.d/default.conf

upstream app {
    server unix:/var/sockets/unicorn.mypage.sock fail_timeout=0;
}

server {

    listen 80;
    server_name mypage.com;

    # Application root, as defined previously
    root /home/rails/mypage/public;

    location ^~ /assets/ {
      gzip_static on;
      expires max;
      add_header Cache-Control public;
    }

    try_files $uri/index.html $uri @app;

    location @app {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_pass http://app;
    }

    error_page 500 502 503 504 /500.html;
    client_max_body_size 4G;
    keepalive_timeout 10;
}

/home/rails/mypage/config/unicorn.rb

working_directory "/home/rails/mypage"

pid "/home/rails/mypage/pids/unicorn.pid"

stderr_path "/home/rails/mypage/log/unicorn.log"
stdout_path "/home/rails/mypage/log/unicorn.log"

listen "/var/sockets/unicorn.mypage.sock", backlog: 1024

worker_processes 2

timeout 30

【问题讨论】:

  • 尝试在socket线下再添加一个listen 3000,直接连接http://localhost:3000看Unicorn/Rails是否正常

标签: ruby-on-rails nginx unicorn


【解决方案1】:

看起来像socket问题,但通常是socket关闭时(111:连接被拒绝),所以我认为这是应用程序问题(高负载,执行缓慢等)。

尝试减少积压并再次查看日志以了解详细信息:

listen "/var/sockets/unicorn.mypage.sock", backlog: 64

:backlog => number of clients

【讨论】:

    【解决方案2】:

    我解决了这个问题。

    这是因为我的独角兽服务器是在开发环境中启动的,而不是在生产环境中。 Unicorn 试图连接到开发数据库,​​但 database.yml 中的开发数据库凭据丢失。 在我在生产环境中开始独角兽之后,一切都很好。

    【讨论】:

      猜你喜欢
      • 2011-11-25
      • 2020-10-17
      • 2011-09-09
      • 2018-07-02
      • 2016-09-21
      • 2014-01-30
      • 2011-05-14
      • 2019-06-05
      • 2015-08-10
      相关资源
      最近更新 更多