问题描述
我正在使用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.
顺便说一句,我最初是按照本教程进行的:
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套接字文件(没有这样的文件或目录)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!