我已经检查了应用程序,一切都很好(代码和应用程序配置),服务器、数据库也正常,在日志中我遇到了这个错误,我已经看过这个 Nginx cannot find unix socket file with Unicorn (no such file or directory)但我真的不知道从哪里开始以实现“只需修改 Unicorn 配置文件中的监听变量。例如:监听“/var/sockets/unicorn.[app name].sock”,然后将 Nginx 配置为代理到您的服务器的所有连接到该套接字文件,例如服务器 unix:/var/sockets/unicorn.[app name].sock fail_timeout=0;"如果有人可以请指点我一些关于如何做到这一点的方向,那就太好了。
我更改了文件,但遇到了同样的错误,我的配置文件是(出于保密原因,我删除了部分文件):
root = ""
working_directory root
pid "#{root}/tmp/pids/unicorn.pid"
stderr_path "#{root}/log/unicorn.log"
stdout_path "#{root}/log/unicorn.log"
listen "/var/sockets/unicorn.camicase.sock"
worker_processes 2
timeout 30
和 nginx 配置
upstream unicorn {
server unix:/var/sockets/unicorn.camicase.sock fail_timeout=0;
}
server {
listen 80;
server_name _;
rewrite ^ https://$host$request_uri? permanent;
}
server {
listen 443;
server_name
root
ssl on;
ssl_certificate
ssl_certificate_key
ssl_session_timeout 5m;
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
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 X-Forwarded-Proto https;
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 4G;
keepalive_timeout 10;
}
最佳答案
所以终于让系统启动并运行了,对于所有面临类似问题的人来说,没有 unicorn 或 Nginx 的知识,这里是步骤:
首先确保两个服务都在运行(unicorn 是应用服务器,nginx 是 http 服务器),两个服务都应该在/etc/init.d/中配置。
停止这两个服务。
检查您在 selinux 中的策略,这是一个很好的问题,关于如何解决 PHP 中的相同错误 nginx error connect to php5-fpm.sock failed (13: Permission denied) ,想法是确保selinux不会干扰socket的读取过程(socket由unicorn创建并由nginx读取)
然后你必须编辑你的配置文件 unicorn.rb 和 nginx.conf,它们都应该指向一个不同于 tmp 的文件夹,这就是为什么 https://serverfault.com/questions/463993/nginx-unix-domain-socket-error/464025#464025
所以最后我的配置看起来像这样:
部分 nginx 配置文件
upstream unicorn {
server unix:/home/myuser/apps/myapp/shared/socket/unicorn.camicase.sock fail_timeout=0;
}
unicorn 配置文件的一部分
listen "/home/deployer/apps/stickystreet/shared/socket/unicorn.camicase.sock"
然后启动 unicorn 和 nginx,如果在连接到上游错误时收到 (13: Permission denied),只需执行 sudo chmod 775 socket/更改您放置 unicorn 套接字要存储的任何文件夹的套接字,然后重新启动nginx 服务。
关于ruby-on-rails - Nginx 无法使用 Unicorn 找到 unix 套接字文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26247242/