Rails 应用程序部署、nginx、unicorn、capistrano 套接字错误

Rails 应用程序部署、nginx、unicorn、capistrano 套接字错误

我正在将一个 Rails 应用程序部署到 Digital Ocean VPS。我已关注https://coderwall.com/p/yz8cha一切事情都完成好了,但是现在浏览器只显示一个空白页。

Nginx 日志包含:

2014/08/04 03:07:20 [crit] 20550#0: *4 connect() to unix:/var/run/unicorn.testvpsdo.sock failed (2: No such file or directory) while connectin$
2014/08/04 03:08:39 [crit] 20550#0: *11 connect() to unix:/var/run/unicorn.testvpsdo.sock failed (2: No such file or directory) while connecti$
2014/08/04 03:08:40 [crit] 20550#0: *11 connect() to unix:/var/run/unicorn.testvpsdo.sock failed (2: No such file or directory) while connecti$
2014/08/04 03:08:41 [crit] 20550#0: *11 connect() to unix:/var/run/unicorn.testvpsdo.sock failed (2: No such file or directory) while connecti$
2014/08/04 03:08:41 [crit] 20550#0: *11 connect() to unix:/var/run/unicorn.testvpsdo.sock failed (2: No such file or directory) while connecti$
2014/08/04 03:08:42 [crit] 20550#0: *11 connect() to unix:/var/run/unicorn.testvpsdo.sock failed (2: No such file or directory) while connecti$
2014/08/04 03:08:42 [crit] 20550#0: *14 connect() to unix:/var/run/unicorn.testvpsdo.sock failed (2: No such file or directory) while connecti$
2014/08/04 03:08:42 [crit] 20550#0: *19 connect() to unix:/var/run/unicorn.testvpsdo.sock failed (2: No such file or directory) while connecti$
2014/08/04 04:15:01 [error] 22883#0: *19 connect() failed (111: Connection refused) while connecting to upstream, client: 202.88.237.208, serv$
2014/08/04 04:40:46 [error] 29378#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 202.88.237.208, serve$
2014/08/04 04:45:22 [error] 29378#0: *10 connect() failed (111: Connection refused) while connecting to upstream, client: 202.88.237.208, serv$
2014/08/04 04:49:48 [crit] 31073#0: *1 connect() to unix:/var/run/unicorn.testvpsdo.sock failed (2: No such file or directory) while connectin$
2014/08/04 04:58:19 [crit] 31073#0: *4 connect() to unix:/var/run/unicorn.testvpsdo.sock failed (2: No such file or directory) while connectin$
2014/08/04 04:58:38 [crit] 31073#0: *7 connect() to unix:/var/run/unicorn.testvpsdo.sock failed (2: No such file or directory) while connectin$
2014/08/04 04:59:45 [crit] 32683#0: *1 connect() to unix:/var/run/unicorn.testvpsdo.sock failed (2: No such file or directory) while connectin$
2014/08/04 05:00:28 [crit] 32683#0: *4 connect() to unix:/var/run/unicorn.testvpsdo.sock failed (2: No such file or directory) while connectin$
2014/08/04 05:00:29 [crit] 32683#0: *4 connect() to unix:/var/run/unicorn.testvpsdo.sock failed (2: No such file or directory) while connectin$
2014/08/04 05:08:15 [crit] 32683#0: *8 connect() to unix:/var/run/unicorn.testvpsdo.sock failed (2: No such file or directory) while connectin$
2014/08/04 05:09:50 [crit] 32683#0: *11 connect() to unix:/var/run/unicorn.testvpsdo.sock failed (2: No such file or directory) while connecti$
2014/08/04 05:30:02 [crit] 32683#0: *14 connect() to unix:/var/run/unicorn.testvpsdo.sock failed (2: No such file or directory) while connecti$

我已经更改了目录,现在显示错误:

2014/08/04 05:34:18 [emerg] 1985#0: invalid host in upstream "/tmp/unicorn.testvpsdo.sock" in /etc/nginx/sites-enabled/testvpsdo:2
2014/08/04 05:36:35 [emerg] 2459#0: invalid host in upstream "/tmp/unicorn.testvpsdo.sock" in /etc/nginx/sites-enabled/testvpsdo:2

Nginx 配置:

 upstream unicorn {
     server unix:/tmp/unicorn.testvpsdo.sock fail_timeout=0;
 }

 server {
     listen 80 default_server deferred;
     # server_name example.com;
     root /home/navin/apps/testvpsdo/current/public;

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

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

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

     error_page 500 502 503 504 /500.html;
     client_max_body_size 20M;
     keepalive_timeout 10;
}

尽管我搜索了很多网站,但我还是不知道如何修复它。

答案1

由于权限问题,nginx 无法访问您的套接字文件。请尝试以下操作:

sudo mkdir /var/sockets
sudo chmod -R 755 /var/sockets
sudo mv /tmp/unicorn.testvpsdo.sock /var/sockets/unicorn.testvpsdo.sock

然后在 nginx.conf 和 unicorn.rb 文件中指定新的套接字目录。重新部署并查看会发生什么。

相关内容