【问题标题】:Nginx and Unicorn - (Connection refused) while connecting to upstreamNginx 和 Unicorn - 连接到上游时(连接被拒绝)
【发布时间】:2013-10-16 04:48:39
【问题描述】:

尝试在 vps 上部署我的第一个 rails 应用程序。我已按照以下设置中的说明进行操作。

https://www.digitalocean.com/community/articles/how-to-1-click-install-ruby-on-rails-on-ubuntu-12-10-with-digitalocean

但我的网站出现 504 网关超时。

在 nginx 日志中,我得到以下信息:

2013/10/16 03:10:45 [error] 19627#0: *82 connect() failed (111: Connection refused) while connecting to upstream, client: 121.218.167.90, server: _, request: "GET / HTTP/1.1", upstream: "http://162.243.39.196:8080/", host: "162.243.39.196"

当我尝试运行独角兽时,我得到以下信息

E, [2013-10-16T04:26:28.530019 #30087] ERROR -- : adding listener failed addr=0.0.0.0:8080 (in use)

我的 nginx 默认文件有以下内容

server {
        listen   80;
        root /home/rails/public;
        server_name _;
        index index.htm index.html;

        location / {
                try_files $uri/index.html $uri.html $uri @app;
        }

        location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|mp3|flv|mpeg|avi)$ {
                        try_files $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_server;
    }

}

我的 /home/unicorn/unicorn.conf 有

listen "127.0.0.1:8080"
worker_processes 2
user "rails"
working_directory "/home/rails"
pid "/home/unicorn/pids/unicorn.pid"
stderr_path "/home/unicorn/log/unicorn.log"
stdout_path "/home/unicorn/log/unicorn.log"

感谢您的帮助。

【问题讨论】:

    标签: ruby-on-rails nginx unicorn


    【解决方案1】:

    您缺少在 proxy_pass http://app_server; 中引用的上游块。您可以像这样将它放在服务器块上方。

    upstream app_server {
        server 127.0.0.1:8080 fail_timeout=0;
    }
    
    server {
        listen   80;
        root /home/rails/public;
        server_name _;
        index index.htm index.html;
        ...
    

    【讨论】:

    • 感谢您的帮助,但不幸的是,这不起作用。我收到以下错误消息: Restarting nginx: nginx: [emerg] duplicate upstream "app_server" in /etc/nginx/sites-enabled/default:1 nginx: configuration file /etc/nginx/nginx.conf test failed
    • 我明白了。你已经有了上游部分。尝试删除重复项,杀死 -9 所有独角兽进程并再次重新启动 nginx 和独角兽。看看它是否有效。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-01
    • 2014-02-26
    • 2012-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-13
    相关资源
    最近更新 更多