Nginx 找不到 Unicorn 的 unix socket 文件(没有这样的文件或目录) [英] Nginx cannot find unix socket file with Unicorn (no such file or directory)

查看:42
本文介绍了Nginx 找不到 Unicorn 的 unix socket 文件(没有这样的文件或目录)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Nginx 和 Unicorn 将 Rails 4 应用程序部署到 Fedora 19 x64 服务器.问题是我在访问地址时出错:很抱歉,出了点问题."

I am deploying a Rails 4 app to a Fedora 19 x64 server using Nginx and Unicorn. The problem is that I get an error when visiting the address: "We're sorry, but something went wrong."

我的 Nginx 错误日志 (/var/log/nginx/error.log) 显示:

My Nginx error log (/var/log/nginx/error.log) shows:

2014/03/08 03:50:12 [warn] 23934#0: conflicting server name "localhost" on 0.0.0.0:80, ignored
2014/03/08 03:50:12 [warn] 23936#0: conflicting server name "localhost" on 0.0.0.0:80, ignored
2014/03/08 03:50:14 [crit] 23939#0: *1 connect() to unix:/tmp/unicorn.[app name].sock failed (2: No such file or directory) while connecting to upstream, client: [client IP], server: localhost, request: "GET /v1/industries/1.xml HTTP/1.1", upstream: "http://unix:/tmp/unicorn.[app name].sock:/v1/industries.json", host: "api.[app name].ca"

据我所知,Nginx 并不知道套接字存在.但是,查看 /tmp,它确实:

As far as I can see from this, Nginx is not aware that the socket exists. However, looking in /tmp, it does:

[root@localhost tmp]# ls
unicorn.[app name].sock

无论我如何修改 Unicorn 配置文件或 Nginx 配置文件,我一直卡在这一点上.两者都被吸引:

I keep getting stuck at this point, no matter how I modify my Unicorn config file or my Nginx config file. Both are attacted:

/var/www/[应用名称]/config/unicorn.rb:

working_directory "/var/www/[app name]"
pid "/var/www/[app name]/pids/unicorn.pid"
stderr_path "/var/www/[app name]/log/unicorn.log"
stdout_path "/var/www/[app name]/log/unicorn.log"
listen "/tmp/unicorn.[app name].sock"
worker_processes 2
timeout 30

/etc/nginx/conf.d/default.conf:

upstream app {
    server unix:/tmp/unicorn.[app name].sock fail_timeout=0;
}
server {
    listen 80;
    server_name localhost;
    root /var/www/[app name]/public;
    try_files $uri/index.html $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;
    }
    error_page 500 502 503 504 /500.html;
    client_max_body_size 4G;
    keepalive_timeout 10;
}

我启动这两个守护进程的方式如下:

The way I have been starting these two daemons is as follows:

unicorn_rails -c /var/www/[app name]/config/unicorn.rb -D -E production
service nginx start

Unicorn 日志不包含相关信息,生产日志也不包含相关信息.这个设置看起来很简单,有人以前经历过吗?感谢您提供的任何帮助.

The Unicorn logs contain no relevant information, nor do the production logs. This setup seems straight forward, has anyone experienced this before? Thanks for any help you can provide.

顺便说一句,我最初是在学习本教程:https://www.digitalocean.com/community/articles/how-to-deploy-rails-apps-using-unicorn-and-nginx-on-centos-6-5

By the way, I was initially following this tutorial: https://www.digitalocean.com/community/articles/how-to-deploy-rails-apps-using-unicorn-and-nginx-on-centos-6-5

推荐答案

经过几个小时和总共 3 杯啤酒后,我设法找出了问题所在.经过数小时的挖掘,我终于遇到了这个服务器故障答案

After many hours and a grand total of 3 beers, I've managed to figure out the problem. After hours of digging, I finally came across this Server Fault answer

通俗地说,在 /tmp(或我发现的 /var/tmp)中创建文件的程序似乎是唯一能够查看该目录中的文件.Unicorn 正在创建 UNIX 套接字文件,但是 Nginx 看不到它.

In layman terms, it appears that programs that create files in /tmp (or /var/tmp as I have discovered) are the only programs that are able to see the files in that directory. Unicorn was creating the UNIX socket file, however Nginx could not see it.

我采用的解决方案是让 Unicorn 在 /var/sockets 中创建套接字.

The solution I have employed is to have Unicorn create sockets in /var/sockets.

这篇关于Nginx 找不到 Unicorn 的 unix socket 文件(没有这样的文件或目录)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆