【问题标题】:connect() to unix:/var/run/unicorn.sock failed (111: Connection refused) while connecting to upstreamconnect() 到 unix:/var/run/unicorn.sock 在连接到上游时失败(111:连接被拒绝)
【发布时间】:2017-07-17 20:54:48
【问题描述】:

我遵循 ruby​​ on rails 一键式部署。数据库做得很好,即使我检查 rails 控制台一切正常

017/02/26 15:34:17 [error] 18564#0: *31 connect() to unix:/var/run/unicorn.sock failed (111: Connection refused) while connecting to upstream, client: 121.52.156.57, server: _, request: "GET / HTTP/1.1", upstream: "http://unix:/var/run/unicorn.sock:/", host: "188.166.157.124"
2017/02/26 15:35:42 [error] 32360#0: *1 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 119.155.34.115, server: _, request: "GET / HTTP/1.1", upstream: "http://unix:/var/run/unicorn.sock/", host: "188.166.157.124"
2017/02/26 15:42:38 [error] 6296#0: *1 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 119.152.140.90, server: _, request: "GET / HTTP/1.1", upstream: "http://unix:/var/run/unicorn.sock/", host: "188.166.157.124"

uncorn.conf 是

listen "unix:/var/run/unicorn.sock"
worker_processes 4
user "rails"
working_directory "/home/rails/company_startup"
pid "/var/run/unicorn.pid"
stderr_path "/var/log/unicorn/unicorn.log"
stdout_path "/var/log/unicorn/unicorn.log"

nginx 是

upstream app_server {
server unix:/var/run/unicorn.sock fail_timeout=0;
}

server {
listen   80;
root /home/rails/nehbor-webserver/public;
server_name _;
index index.htm index.html;
client_max_body_size 1M;
location / {
        try_files $uri/index.html $uri.html $uri @app;
}

location ~* ^.+\.(jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|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;
}
}

【问题讨论】:

    标签: ruby-on-rails ruby nginx digital-ocean unicorn


    【解决方案1】:

    根据unicorn documentation,我觉得你应该把配置中listen方法中的unix部分去掉,改成listen "/var/run/unicorn.sock"

    listen 3000 # listen to port 3000 on all TCP interfaces
    listen "127.0.0.1:3000"  # listen to port 3000 on the loopback interface
    listen "/path/to/.unicorn.sock" # listen on the given Unix domain socket
    listen "[::1]:3000" # listen to port 3000 on the IPv6 loopback interface
    

    【讨论】:

    【解决方案2】:

    简而言之,nginx 正在尝试重定向到您的应用程序,但它不能。除了基本的配置和结构之外,我认为最常见的问题与:

    • 端口
    • 套接字
    • 对我来说(使用 aws ec2),我使用的域是通过我的 dns 注册器上的 cname 记录链接的。 ip改变了,改变了域服务器名称,我的记录没有更新。我只是将它从 cname 记录名称更改为我的新弹性域名。

    【讨论】:

      猜你喜欢
      • 2015-06-04
      • 1970-01-01
      • 2020-03-14
      • 2015-04-03
      • 2022-01-18
      • 2014-02-26
      • 2012-11-21
      • 2017-07-08
      • 2016-11-20
      相关资源
      最近更新 更多