简体   繁体   中英

connect() to unix:/var/run/unicorn.sock failed (111: Connection refused) while connecting to upstream

I follow ruby on rails one app click deployment. Database done well, even I check rails console everything working fine

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 is

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 is

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

According to the unicorn documentation , I think you should remove the unix part from the listen method in the configuration and change it to 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

In short nginx is trying to re-direct to your app but it can't. Outside of basic configuration thing and structure, I think the most common issue is related to:

  • ports
  • sockets
  • and for me (using aws ec2), I was using a domain that was linked via a cname record on my dns registar. The ip changed which changed domain server name and my record wasn't updated. I just changed it from the cname record name to my new elastic domain name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM