ruby-on-rails - connect() 到 unix :/var/run/unicorn. 连接到上游时 sock 失败(111:连接被拒绝)

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

我遵循 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;
}
}

最佳答案

根据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

关于ruby-on-rails - connect() 到 unix :/var/run/unicorn. 连接到上游时 sock 失败(111:连接被拒绝),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42482447/

相关文章:

django - 在 Google App Engine 上为 Django 应用程序启用 CORS

php - Nginx 从不正确的根目录读取站点文件

ruby-on-rails - 无法从 View 上的 Controller 中看到变量 - Rails 6

ruby-on-rails - 无法安装 gem debugger -v '1.6.5'

ruby-on-rails - 尝试在 ruby​​ 中创建 pin 时如何修复 NoMethodError?

ruby-on-rails - rails 4.0 上的 haml-rails?

ruby-on-rails - 如何将 Rack 中间件添加到 gem 的 Rails 应用程序

ruby-on-rails - 事件记录导入正在创建重复记录

mysql - 在 64 位 ruby​​ 和 64 位 Windows 上安装 ruby​​ on Rails 的 mysql2 扩展

nginx - 为什么 nginx 总是以默认站点响应,即使它现在应该响应?