###前提・実現したいこと
nginxを正しく設定してrailsアプリをunicorn経由で表示したいです。
###発生している問題・エラーメッセージ
【ブラウザ】
502 Bad Gateway
【エラーログ】
2017/02/07 00:52:16 [error] 7050#7050: *9 connect() to unix:/var/run/unicorn/unicorn.sock failed (111: Connection refused) while connecting to upstream, client: xxx.xxx.xxx.xxx, server: anime-report, request: "GET / HTTP/1.1", upstream: "http://unix:/var/run/unicorn/unicorn.sock:/", host: "xxx.xx.xxx.xx"
ポート番号がいけないのでしょうか。。。
###該当のソースコード
【config/unicorn.rb】
worker_processes 2 working_directory "/home/anime/app/anime-report" listen "/var/run/unicorn/unicorn.sock" pid "/var/run/unicorn/unicorn.pid" preload_app true
【/etc/nginx/nginx.conf】
user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; 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; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf; }
【/etc/nginx/conf.d/sample.conf】
upstream unicorn-unix-domain-socket { server unix:/var/run/unicorn/unicorn.sock fail_timeout=0; } upstream unicorn-tcp { server xxx.xx.xxx.xx; } server { listen 80; server_name anime-report; root /home/anime/app/anime-report/public; access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; location / { proxy_pass http://unicorn-unix-domain-socket; } }
ご経験ある方、ご指摘お願いします。
###追加
【INETに変更後】
2017/02/07 10:48:29 [error] 7984#7984: *7 connect() failed (111: Connection refused) while connecting to upstream, client: 126.129.108.242, server: anime-report, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:3000/", host: "xxx.xx.xxx.xx"
[anime@tk2-241-30026 etc]$ service nginx configtest nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied) 2017/02/07 11:12:32 [warn] 8111#8111: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:2 nginx: the configuration file /etc/nginx/nginx.conf syntax is ok 2017/02/07 11:12:32 [emerg] 8111#8111: open() "/var/run/nginx.pid" failed (13: Permission denied) nginx: configuration file /etc/nginx/nginx.conf test failed
[anime@tk2-241-30026 etc]$ ps aux | grep nginx root 8080 0.0 0.0 45096 1044 ? Ss 10:57 0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf nginx 8081 0.0 0.1 45492 2124 ? S 10:57 0:00 nginx: worker process anime 8115 0.0 0.0 103328 868 pts/0 S+ 11:16 0:00 grep nginx
[anime@tk2-241-30026 etc]$ sudo tcpdump -n icmp tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes 11:48:01.461745 IP 157.119.234.13 > 160.16.198.30: ICMP echo request, id 23721, seq 2846, length 64 11:48:01.461908 IP 160.16.198.30 > 157.119.234.13: ICMP echo reply, id 23721, seq 2846, length 64 11:48:03.591478 IP 139.5.110.36 > 160.16.198.30: ICMP echo request, id 23756, seq 631, length 64 11:48:03.591622 IP 160.16.198.30 > 139.5.110.36: ICMP echo reply, id 23756, seq 631, length 64 11:48:05.294145 IP 157.119.234.13 > 160.16.198.30: ICMP echo request,
[anime@tk2-241-30026 ~]$ ls -l /var/ 合計 76 drwxr-xr-x. 2 root root 4096 12月 6 19:09 2016 account drwxr-xr-x. 10 root root 4096 1月 19 23:09 2017 cache drwxr-xr-x. 2 root root 4096 11月 19 00:19 2016 crash drwxr-xr-x. 2 root root 4096 11月 22 21:29 2013 cvs drwxr-xr-x. 3 root root 4096 12月 6 19:09 2016 db drwxr-xr-x. 3 root root 4096 12月 6 19:09 2016 empty drwxr-xr-x. 2 root root 4096 9月 23 20:50 2011 games drwxr-xr-x. 27 root root 4096 2月 7 03:02 2017 lib drwxr-xr-x. 2 root root 4096 9月 23 20:50 2011 local drwxrwxr-x. 5 root lock 4096 2月 7 03:02 2017 lock drwxr-xr-x. 9 root root 4096 2月 5 04:51 2017 log lrwxrwxrwx. 1 root root 10 1月 18 23:08 2017 mail -> spool/mail drwxr-xr-x. 2 root root 4096 9月 23 20:50 2011 nis drwxr-xr-x. 2 root root 4096 9月 23 20:50 2011 opt drwxr-xr-x. 2 root root 4096 9月 23 20:50 2011 preserve drwxr-xr-x. 20 root root 4096 2月 7 10:57 2017 run drwxr-xr-x. 11 root root 4096 12月 6 19:09 2016 spool drwxrwxrwt. 5 root root 4096 2月 7 12:08 2017 tmp drwxr-xr-x 6 root root 4096 1月 19 11:25 2017 www drwxr-xr-x. 2 root root 4096 9月 23 20:50 2011 yp
[anime@tk2-241-30026 ~]$ ls -l /var/run/ 合計 108 drwxr-xr-x. 2 root root 4096 5月 11 06:09 2016 ConsoleKit drwxr-xr-x. 2 root root 4096 5月 12 05:43 2016 abrt -rw-r--r-- 1 root root 5 1月 28 12:53 2017 acpid.pid srw-rw-rw- 1 root root 0 1月 28 12:53 2017 acpid.socket -rw-r--r-- 1 root root 5 1月 28 12:53 2017 atd.pid drwxr-xr-x. 2 root root 4096 5月 11 08:18 2016 console ---------- 1 root root 0 1月 28 12:53 2017 cron.reboot -rw-r--r-- 1 root root 5 1月 28 12:53 2017 crond.pid drwxr-xr-x. 2 root root 4096 4月 22 19:52 2015 dbus drwxr-xr-x. 2 root root 4096 1月 28 12:53 2017 fail2ban drwxr-xr-x. 2 root root 4096 5月 11 08:18 2016 faillock drwx------. 2 haldaemon haldaemon 4096 10月 15 19:49 2014 hald drwx--x--- 2 root apache 4096 2月 1 21:34 2017 httpd -rw-r--r-- 1 root root 5 1月 28 12:53 2017 irqbalance.pid drwx------. 2 root root 4096 8月 24 03:37 2016 lvm drwx------. 2 root root 4096 7月 13 00:43 2016 mdadm drwxr-xr-x 2 mysql mysql 4096 1月 28 12:53 2017 mysqld drwxrwxr-x. 2 root root 4096 7月 13 01:40 2016 netreport -rw-r--r-- 1 root root 5 2月 7 10:57 2017 nginx.pid -rw-r--r-- 1 root root 4 1月 28 12:53 2017 ntpd.pid drwxr-xr-x. 2 root root 4096 8月 12 02:59 2014 plymouth drwxr-xr-x. 4 root root 4096 12月 6 19:09 2016 pm-utils drwxr-xr-x. 2 root root 4096 3月 25 19:24 2015 saslauthd drwxr-xr-x. 2 root root 4096 5月 11 08:18 2016 sepermit drwxr-xr-x. 2 root root 4096 5月 11 07:59 2016 setrans -rw-r--r-- 1 root root 6 2月 2 09:53 2017 sshd.pid -rw------- 1 root root 5 1月 28 12:53 2017 syslogd.pid drwxrwxrwx 2 root root 4096 2月 6 21:39 2017 unicorn -rw-rw-r-- 1 root utmp 2688 2月 7 10:42 2017 utmp
[anime@tk2-241-30026 ~]$ ls -l /var/run/unicorn/ 合計 4 -rw-r--r-- 1 anime anime 5 2月 6 21:39 2017 unicorn.pid srwxrwxrwx 1 anime anime 0 2月 6 21:39 2017 unicorn.sock
[anime@tk2-241-30026 log]$ cat unicorn-stderr.log I, [2017-02-06T15:49:11.050366 #2363] INFO -- : Refreshing Gem list DEPRECATION WARNING: `config.serve_static_files` is deprecated and will be removed in Rails 5.1. Please use `config.public_file_server.enabled = false` instead. (called from block in <top (required)> at /home/anime/var/www/anime-report/config/environments/production.rb:25) I, [2017-02-06T15:49:12.997127 #2363] INFO -- : listening on addr=/home/anime/var/www/anime-report/tmp/sockets/unicorn.sock fd=8 I, [2017-02-06T15:49:12.997561 #2363] INFO -- : worker=0 spawning... I, [2017-02-06T15:49:13.002448 #2363] INFO -- : worker=1 spawning... I, [2017-02-06T15:49:13.005643 #2363] INFO -- : master process ready I, [2017-02-06T15:49:13.300405 #2369] INFO -- : worker=1 ready I, [2017-02-06T15:49:13.353984 #2366] INFO -- : worker=0 ready
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/02/07 01:44
2017/02/07 01:51
2017/02/07 01:54
2017/02/07 03:00
2017/02/07 03:01
2017/02/07 03:10
2017/02/07 03:12
2017/02/07 03:14
2017/02/07 03:19
2017/02/07 04:41
2017/02/07 08:53
2017/02/07 14:08