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 獨角獸輸出。
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
這是 ps -ef | nginx 的 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; }
我相信您的 nginx 配置中的行
server unix:/var/www/reportcard/dev/pids/unicorn.pid fail_timeout=0;
實際上應該是您的套接字而不是您的 pid。