无法让 Unicorn 与 Nginx 通信

无法让 Unicorn 与 Nginx 通信

我已经看过这里的所有其他问题,但似乎没有一个对我有用。每当我尝试访问我的网站时,我都会通过 nginx 日志收到连接被拒绝的错误。我假设存在权限问题或有人在错误的端口上监听。这是我收到的错误。

2014/10/06 10:13:50 [crit] 18027#0: *1 connect() to unix:/var/www/reportcard/dev/pids/unicorn.pid 失败(13:权限被拒绝)连接到上游,客户端:my_ip,服务器:dev.reportcard.io,请求:“GET / HTTP/1.1”,上游:“http://unix:/var/www/reportcard/dev/pids/unicorn.pid:/”,主机:“dev.reportcard.io”

我有一个位于 /var/www/reportcard/dev 的 rails 应用程序,它的 ls -l 输出如下:

drwxr-xr-x 9 ghost    ghost    4096 Sep 19 11:38 ghost
drwxr-xr-x 3 www-data www-data 4096 Jun  2 15:21 park
drwxr-xr-x 3 willkara www-data 4096 Jul 29 15:33 reportcard

Here's the ls -l for reportcard

drwxr-xr-x 14 willkara www-data 4096 Jul 29 15:55 dev
-rwxr-xr-x  1 willkara www-data   56 Jul 28 20:17 index.html

这是 ps -ef | grep unicorn 的输出。

root@slimer:/var/www# ps -ef | grep unicorn
willkara 14265     1  0 15:54 ?        00:00:00 unicorn_rails master -c config/unicorn.rb -D -E development
willkara 14268 14265  0 15:54 ?        00:00:02 unicorn_rails worker[0] -c config/unicorn.rb -D -E development

以下是 nginx 的 ps -ef | grep 输出

willkara@slimer:/var/www/reportcard/dev$ ps -ef | grep nginx
root     18026     1  0 10:13 ?        00:00:00 nginx: master process /usr/sbin/nginx
www-data 18027 18026  0 10:13 ?        00:00:00 nginx: worker process
www-data 18028 18026  0 10:13 ?        00:00:00 nginx: worker process
willkara 18073 19220  0 10:14 pts/0    00:00:00 grep --color=auto nginx

独角兽配置文件​​如下所示:

  1 # Set the working application directory
  2 # working_directory "/path/to/your/app"
  3 working_directory "/var/www/reportcard/dev"
  4
  5 # Unicorn PID file location
  6 # pid "/path/to/pids/unicorn.pid"
  7 pid "/var/www/reportcard/dev/pids/unicorn.pid"
  8
  9 # Path to logs
 10 # stderr_path "/path/to/log/unicorn.log"
 11 # stdout_path "/path/to/log/unicorn.log"
 12 stderr_path "/var/www/reportcard/dev/log/unicorn.log"
 13 stdout_path "/var/www/reportcard/dev/log/unicorn.log"
 14
 15 # Unicorn socket
 16 listen "/tmp/unicorn.reportcard.sock"
 17
 18 # Number of processes
 19 # worker_processes 4
 20 worker_processes 2
 21
 22 # Time-out
 23 timeout 30

该站点的 nginx 配置如下:

upstream app {
    # Path to Unicorn SOCK file, as defined previously
    server unix:/var/www/reportcard/dev/pids/unicorn.pid fail_timeout=0;
}

server {


    listen 80;
    server_name dev.reportcard.io;

    # Application root, as defined previously
    root /var/www/reportcard/dev/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;
}

答案1

我相信你的 nginx 配置中有这样一行

server unix:/var/www/reportcard/dev/pids/unicorn.pid fail_timeout=0;

实际上应该是你的套接字而不是你的 pid。

相关内容