前提・実現したいこと
プログラミング初心者です。
$ sudo service nginx startの実行に失敗し、アプリがブラウザ上に表示されません。
ブラウザのアドレス欄には、以下のとおり入力しました。
http://xx.xxx.xx.xx/(Elastic IP アドレス)
どうしてブラウザ上に表示されないのでしょうか。
以下に情報を記載させていただきますので、お気づきの点がございましたらご教示いただけますと幸いです。
$ sudo nginx -t 実行結果
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
$ ps -ef | grep unicorn | grep -v grep 実行結果
asami 4290 1 0 5月08 ? 00:00:01 unicorn_rails master -c /var/www/rails/アプリ名/config/unicorn.conf.rb -D -E production asami 4293 4290 0 5月08 ? 00:00:00 unicorn_rails worker[0] -c /var/www/rails/アプリ名/config/unicorn.conf.rb -D -E production asami 4294 4290 0 5月08 ? 00:00:00 unicorn_rails worker[1] -c /var/www/rails/アプリ名/config/unicorn.conf.rb -D -E production
$ curl http://127.0.0.1/ 実行結果
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Welcome to Amazon Linux 2</title> <style rel="stylesheet" type="text/css"> html { background-color: white; font-family: "DejaVu Sans", "Liberation Sans", sans-serif; margin: 10% 20%; } body { margin:0; padding:0; background: white; } a { color: #007eb9; } </style> </head> <body> <p>Thank you for using <a href="https://aws.amazon.com/amazon-linux-2/">Amazon Linux 2</a>.<p> <p>Now that you have it installed, find announcements and discussion in <a href="https://forums.aws.amazon.com/forum.jspa?forumID=228">the AWS Discussion Forums</a>. Also try <a href="https://aws.amazon.com/documentation/">AWS documentation</a>.</p> </body> </html>
http://xx.xxx.xx.xx/(Elastic IP アドレス) 実行結果
AWSの状況
①EC2/インスタンス
/etc/nginx/conf.d/アプリ名.confの中身
# log directory error_log /var/www/rails/アプリ名/log/nginx.error.log; access_log /var/www/rails/アプリ名/log/nginx.access.log; # max body size client_max_body_size 2G; upstream app_server { # for UNIX domain socket setups server unix:/var/www/rails/アプリ名/tmp/sockets/unicorn.sock fail_timeout=0; } upstream unicorn { server unix:/var/www/rails/アプリ名/tmp/sockets/unicorn.sock; } server { listen 80; server_name 18.180.71.74; # nginx so increasing this is generally safe... keepalive_timeout 5; # path for static files root /var/www/rails/アプリ名/public; # page cache loading try_files $uri/index.html $uri.html $uri @app; location @app { # HTTP headers proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://app_server; } location @unicorn { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_pass http://unicorn; } # Rails error pages error_page 500 502 503 504 /500.html;
【補足1】nginxのログ状況
$ sudo nano /var/log/nginx/access.log 実行結果
111.239.181.40 - - [09/May/2021:11:17:42 +0000] "GET / HTTP/1.1" 301 5 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36$ 188.166.70.83 - - [09/May/2021:11:20:20 +0000] "GET / HTTP/1.0" 500 1635 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:82.0) Gecko/2010010$ 127.0.0.1 - - [09/May/2021:11:32:28 +0000] "GET / HTTP/1.1" 200 732 "-" "curl/7.61.1" "-" 188.166.70.83 - - [09/May/2021:11:48:07 +0000] "GET /_ignition/execute-solution HTTP/1.1" 301 5 "-" "python-requests/2.18.4" "-" 132.145.196.125 - - [09/May/2021:12:15:13 +0000] "POST / HTTP/1.1" 307 5 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like $ 132.145.196.125 - - [09/May/2021:12:15:15 +0000] "GET /.env HTTP/1.1" 301 5 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, li$ 124.219.132.185 - - [09/May/2021:12:35:52 +0000] "GET / HTTP/1.1" 301 5 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHT$ 170.254.75.31 - - [09/May/2021:12:44:03 +0000] "GET / HTTP/1.1" 301 5 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like$ 47.241.125.249 - - [09/May/2021:13:00:54 +0000] "\x05\x01\x00" 400 157 "-" "-" "-" 47.241.125.249 - - [09/May/2021:13:01:20 +0000] "GET http://passport.baidu.com/ HTTP/1.1" 200 732 "-" "-" "-" 47.241.125.249 - - [09/May/2021:13:02:16 +0000] "\x04\x01\x00Pg)\xA7\xEA\x00" 400 157 "-" "-" "-"
$ sudo service nginx status 実行結果
Redirecting to /bin/systemctl status nginx.service ● nginx.service - The nginx HTTP and reverse proxy server Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled) Active: inactive (dead) 5月 10 14:23:27 ip-10-0-0-248.ap-northeast-1.compute.internal systemd[1]: Failed to start The nginx HTTP and reverse proxy server. 5月 10 14:23:27 ip-10-0-0-248.ap-northeast-1.compute.internal systemd[1]: Unit nginx.service entered failed state. 5月 10 14:23:27 ip-10-0-0-248.ap-northeast-1.compute.internal systemd[1]: nginx.service failed. 5月 10 14:26:24 ip-10-0-0-248.ap-northeast-1.compute.internal systemd[1]: Starting The nginx HTTP and reverse proxy server... 5月 10 14:26:24 ip-10-0-0-248.ap-northeast-1.compute.internal nginx[20542]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok 5月 10 14:26:24 ip-10-0-0-248.ap-northeast-1.compute.internal nginx[20542]: nginx: configuration file /etc/nginx/nginx.conf test is su...sful 5月 10 14:26:24 ip-10-0-0-248.ap-northeast-1.compute.internal systemd[1]: Failed to read PID from file /run/nginx.pid: Invalid argument 5月 10 14:26:24 ip-10-0-0-248.ap-northeast-1.compute.internal systemd[1]: Started The nginx HTTP and reverse proxy server. 5月 10 15:29:29 ip-10-0-0-248.ap-northeast-1.compute.internal systemd[1]: Stopping The nginx HTTP and reverse proxy server... 5月 10 15:29:29 ip-10-0-0-248.ap-northeast-1.compute.internal systemd[1]: Stopped The nginx HTTP and reverse proxy server. Hint: Some lines were ellipsized, use -l to show in full.
【補足2】unicornのログ状況
/var/www/rails/アプリ名/log に移動し、
$ sudo less unicorn.logを実行した結果
I, [2021-05-04T16:45:51.374358 #7310] INFO -- : Refreshing Gem list I, [2021-05-04T16:45:53.511544 #7310] INFO -- : listening on addr=/var/www/rails/アプリ名/tmp/sockets/.unicorn.sock fd=9 I, [2021-05-04T16:45:53.517088 #7310] INFO -- : master process ready I, [2021-05-04T16:45:53.521522 #7312] INFO -- : worker=0 ready I, [2021-05-04T16:45:53.522770 #7313] INFO -- : worker=1 ready I, [2021-05-05T04:19:37.632516 #7310] INFO -- : reaped #<Process::Status: pid 7312 exit 0> worker=0 I, [2021-05-05T04:19:37.634294 #7310] INFO -- : reaped #<Process::Status: pid 7313 exit 0> worker=1 I, [2021-05-05T04:19:37.634380 #7310] INFO -- : master complete I, [2021-05-05T04:43:27.493213 #7551] INFO -- : Refreshing Gem list I, [2021-05-05T04:43:30.223796 #7551] INFO -- : unlinking existing socket=/var/www/rails/アプリ名/tmp/sockets/.unicorn.sock I, [2021-05-05T04:43:30.223963 #7551] INFO -- : listening on addr=/var/www/rails/アプリ名/tmp/sockets/.unicorn.sock fd=9 I, [2021-05-05T04:43:30.247530 #7551] INFO -- : master process ready I, [2021-05-05T04:43:30.253070 #7555] INFO -- : worker=1 ready I, [2021-05-05T04:43:30.253508 #7554] INFO -- : worker=0 ready I, [2021-05-06T13:26:07.863029 #7551] INFO -- : reaped #<Process::Status: pid 7554 exit 0> worker=0 I, [2021-05-06T13:26:07.863371 #7551] INFO -- : reaped #<Process::Status: pid 7555 exit 0> worker=1 I, [2021-05-06T13:26:07.863439 #7551] INFO -- : master complete I, [2021-05-06T15:10:40.684478 #3957] INFO -- : Refreshing Gem list I, [2021-05-06T15:10:46.922051 #3957] INFO -- : unlinking existing socket=/var/www/rails/アプリ名/tmp/sockets/.unicorn.sock I, [2021-05-06T15:10:46.922219 #3957] INFO -- : listening on addr=/var/www/rails/アプリ名/tmp/sockets/.unicorn.sock fd=9 I, [2021-05-06T15:10:46.939327 #3957] INFO -- : master process ready I, [2021-05-06T15:10:46.943953 #3960] INFO -- : worker=0 ready I, [2021-05-06T15:10:46.945229 #3961] INFO -- : worker=1 ready I, [2021-05-07T14:10:30.770122 #3957] INFO -- : reaped #<Process::Status: pid 3960 exit 0> worker=0 I, [2021-05-07T14:10:30.770737 #3957] INFO -- : reaped #<Process::Status: pid 3961 exit 0> worker=1 I, [2021-05-07T14:10:30.770821 #3957] INFO -- : master complete I, [2021-05-07T14:35:51.235962 #3443] INFO -- : Refreshing Gem list I, [2021-05-07T14:35:53.728166 #3443] INFO -- : unlinking existing socket=/var/www/rails/アプリ名/tmp/sockets/.unicorn.sock I, [2021-05-07T14:35:53.728336 #3443] INFO -- : listening on addr=/var/www/rails/アプリ名/tmp/sockets/.unicorn.sock fd=9 I, [2021-05-07T14:35:53.742418 #3443] INFO -- : master process ready I, [2021-05-07T14:35:53.746745 #3447] INFO -- : worker=1 ready I, [2021-05-07T14:35:53.748069 #3446] INFO -- : worker=0 ready I, [2021-05-08T09:03:57.347631 #3443] INFO -- : reaped #<Process::Status: pid 3446 exit 0> worker=0 I, [2021-05-08T09:03:57.348178 #3443] INFO -- : reaped #<Process::Status: pid 3447 exit 0> worker=1 I, [2021-05-08T09:03:57.348261 #3443] INFO -- : master complete I, [2021-05-08T10:32:02.517721 #3826] INFO -- : Refreshing Gem list I, [2021-05-08T10:32:05.086000 #3826] INFO -- : unlinking existing socket=/var/www/rails/アプリ名/tmp/sockets/.unicorn.sock I, [2021-05-08T10:32:05.086181 #3826] INFO -- : listening on addr=/var/www/rails/アプリ名/tmp/sockets/.unicorn.sock fd=9
【補足3】バージョン
macOs Catalina 10.15.7 Nginx 1.16.1 Unicorn 6.0.0 Rails 6.0.3 Ruby 2.7.2p137
以上になります。
よろしくお願いいたします。
回答2件
あなたの回答
tips
プレビュー