nginx+unicornでrailsを動かそうとしてる。
unicornの起動はできたっぽいけどnginx側でエラーする。
症状まとめ
環境
- centos7
- unicorn v5.0.1
- nginx/1.8.0
/var/log/nginx/error.log
2015/12/27 22:53:49 [crit] 30088#0: *109 connect() to unix:/tmp/unicorn-unityroom.com.socket failed (2: No such file or directory) while connecting to upstream, client: 60.238.252.251, server: naichilab.com, request: "GET / HTTP/1.1", upstream: "http://unix:/tmp/unicorn-unityroom.com.socket:/500.html", host: "naichilab.com"
~/shared/log/unicorn.stderr.log
I, [2015-12-27T22:57:35.698916 #15321] INFO -- : reaped #<Process::Status: pid 15325 exit 0> worker=0 I, [2015-12-27T22:57:35.699033 #15321] INFO -- : reaped #<Process::Status: pid 15328 exit 0> worker=1 I, [2015-12-27T22:57:35.699116 #15321] INFO -- : master complete I, [2015-12-27T22:57:36.170900 #18582] INFO -- : Refreshing Gem list I, [2015-12-27T22:57:37.387321 #18582] INFO -- : unlinking existing socket=/tmp/unicorn-unityroom.com.socket I, [2015-12-27T22:57:37.387507 #18582] INFO -- : listening on addr=/tmp/unicorn-unityroom.com.socket fd=10 I, [2015-12-27T22:57:37.403895 #18582] INFO -- : master process ready I, [2015-12-27T22:57:37.404796 #18586] INFO -- : worker=0 ready I, [2015-12-27T22:57:37.407383 #18589] INFO -- : worker=1 ready
/etc/nginx/nginx.conf
user nginx; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; worker_processes 2; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; server_names_hash_bucket_size 64; client_max_body_size 64m; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main buffer=16k; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; keepalive_requests 100; #gzip on; upstream unicorn { server unix:/tmp/unicorn-unityroom.com.socket; } include /etc/nginx/conf.d/*.conf; }
/tmp/unicorn-unityroom.com.socket
# ls -la /tmp/ | grep unicorn srwxrwxrwx 1 unityroom_production unityroom_production 0 12月 27 22:57 unicorn-unityroom.com.socket
どーみても存在してる。 なぜ見えない。
ぐぐった
- http://blog.tnantoka.com/posts/49/versions/current
RedmineをCentOS 7上で動かすーUnicornとNginx編 - ソフトウェアエンジニアリング - Torutk
Making Fedora 17, Unicorn and nginx work together - Conecuh Software
PrivateTmpっていうののせいで/tmp上のファイルを他のプロセスと共有できないみたい。
対応
ソケットファイルを別の場所に作るようにする。
変更前:/tmp/unicorn-unityroom.com.socket
変更後:#{app_shared_path}/tmp/unicorn.sock
エラーが変わった
2015/12/27 23:39:00 [crit] 23374#0: *1 connect() to unix:/home/unityroom_production/shared/tmp/unicorn.sock failed (13: Permission denied) while connecting to upstream, client: 60.238.252.251, server: naichilab.com, request: "GET / HTTP/1.1", upstream: "http://unix:/home/unityroom_production/shared/tmp/unicorn.sock:/500.html", host: "naichilab.com"
$ ls -la srwxrwxrwx 1 unityroom_production unityroom_production 0 12月 27 23:38 unicorn.sock
この頭にあるs
ってなんだっけなぁ。