nginxのwebサイトアクセス時にエラーページが表示されるが、エラーログが出力されないので原因が分からない。
ここに実現したいことを箇条書きで書いてください。
- エラーログが出力されるようにする
- エラーページ発生時のエラーログの確認
前提
- AWS lightsailでlinux2サーバーを立ち上げている。
- Nginx / PHP / MariaDBのミドルウェアをインストール
- WordPressをインストールしBlogサイトの立ち上げをしたい
- 参考サイトhttps://kacfg.com/ec2-wordpress/
ここに質問の内容を詳しく書いてください。
- 一通りの設定が完了しサーバーのIPアドレスからwebサイト接続を試みるもenginxのエラーページが表示される。
- sudo vi /var/log/nginx/error.logでエラーログを確認するも、ある時点までのエラーログは出ているがエラーページを表示させた時のエラーが出力されていない。→エラーページ表示時のエラーログを確認したい。
現状確認できている内容
/var/log/nginx/error.logの中身
2023/04/04 15:30:53 [emerg] 2613#2613: "location" directive is not allowed here in /etc/nginx/nginx.conf:85 2023/04/04 15:33:27 [emerg] 2676#2676: "location" directive is not allowed here in /etc/nginx/nginx.conf:85 2023/04/04 16:02:17 [emerg] 3407#3407: "location" directive is not allowed here in /etc/nginx/nginx.conf:82 2023/04/04 16:47:31 [error] 3066#3066: *2 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 118.156.225.222, server: _, request: "GET /favicon.ico HTTP/1.1", host: "18.178.53.49", referrer: "http://18.178.53.49/index2.php" 2023/04/04 17:00:19 [error] 3066#3066: *7 open() "/usr/share/nginx/html/dispatch.asp" failed (2: No such file or directory), client: 193.32.162.159, server: _, request: "GET /dispatch.asp HTTP/1.1", host: "18.178.53.49" 2023/04/04 18:06:37 [error] 3066#3066: *56 open() "/usr/share/nginx/html/dispatch.asp" failed (2: No such file or directory), client: 193.32.162.159, server: _, request: "GET /dispatch.asp HTTP/1.1", host: "18.178.53.49" 2023/04/04 18:21:50 [error] 3066#3066: *61 open() "/usr/share/nginx/html/client/get_targets" failed (2: No such file or directory), client: 170.64.161.98, server: _, request: "GET /client/get_targets HTTP/1.1", host: "18.178.53.49" 2023/04/04 18:21:50 [error] 3066#3066: *62 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 170.64.161.98, server: _, request: "GET /upl.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "18.178.53.49"
/etc/nginx/nginx.confの中身
# For more information on configuration, see: # * Official English Documentation: http://nginx.org/en/docs/ # * Official Russian Documentation: http://nginx.org/ru/docs/ user nginx; worker_processes auto; error_log /var/log/nginx/error.log debug; pid /run/nginx.pid; # Load dynamic modules. See /usr/share/doc/nginx/README.dynamic. include /usr/share/nginx/modules/*.conf; events { worker_connections 1024; } http { 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; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 4096; include /etc/nginx/mime.types; default_type application/octet-stream; # Load modular configuration files from the /etc/nginx/conf.d directory. # See http://nginx.org/en/docs/ngx_core_module.html#include # for more information. include /etc/nginx/conf.d/*.conf; server { listen 80; listen [::]:80; server_name _; root /usr/share/nginx/html; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; error_page 404 /404.html; location = /404.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } } # Settings for a TLS enabled server. # # server { # listen 443 ssl http2; # listen [::]:443 ssl http2; # server_name _; # root /usr/share/nginx/html; # # ssl_certificate "/etc/pki/nginx/server.crt"; # ssl_certificate_key "/etc/pki/nginx/private/server.key"; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 10m; # ssl_ciphers PROFILE=SYSTEM; # ssl_prefer_server_ciphers on; # # # Load configuration files for the default server block. # include /etc/nginx/default.d/*.conf; # # error_page 404 /404.html; # location = /40x.html { # } # # error_page 500 502 503 504 /50x.html; # location = /50x.html { # } # # location ~ \.php$ { # root /usr/share/nginx/html; # fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; # include fastcgi_params; # } } 89,1 末尾
試したこと
- エラーログのパーミッションを変更した。
$ ls -l /var/log/nginx/error.log -rw-r-----. 1 nginx nginx 6929 4月 5 11:15 /var/log/nginx/error.log
- タイムゾーンをASIA/TOKYOに変更
$ timedatectl Local time: 木 2023-04-06 08:43:54 JST Universal time: 水 2023-04-05 23:43:54 UTC RTC time: 水 2023-04-05 23:43:54 Time zone: Asia/Tokyo (JST, +0900) NTP enabled: yes NTP synchronized: yes RTC in local TZ: no DST active: n/a
nginxの構文チェック実行
$ sudo nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
logレベルをdebugにした。
user nginx; worker_processes auto; error_log /var/log/nginx/error.log debug; pid /run/nginx.pid;
よろしくお願いいたします。
追記
###追記②
/var/log/nginx/access.log
- - [06/Apr/2023:08:52:33 +0000] "GET / HTTP/1.1" 500 3708 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36" "-" - - [06/Apr/2023:08:52:33 +0000] "GET /favicon.ico HTTP/1.1" 404 3665 "http://18.178.53.49/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36" "-" "/var/log/nginx/access.log" 282L, 55659B
###追記③
ファビコンのログ出ていたため、nginxの設定ファイルにファビコン参照を無効にする記述をしました。
server { location = /favicon.ico { log_not_found off; } }
これを行ったあと、構文チェックをし、OKだったため再度webにアクセスしました。
/var/log/nginx/error.log
2023/04/06 22:32:23 [debug] 3988#3988: bind() 0.0.0.0:80 #6 2023/04/06 22:32:23 [debug] 3988#3988: bind() [::]:80 #6 2023/04/06 22:32:23 [debug] 3988#3988: counter: 00007FE6BC83E080, 1
ログが出てきました!
/var/log/nginx/access.log
- - [06/Apr/2023:13:42:07 +0000] "GET / HTTP/1.1" 500 3708 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36" "-"
サーバー内部で500エラーが出ていることまで分かりました。
###追記④
nginx.conf からinclude している設定ファイル(/etc/nginx/conf.d/*.conf)にあるphp-fpmの設定ファイル
※すみません、外部PCからLightsailでssh接続しているため、画像の添付になります。
sudo vim /etc/nginx/conf.d/php-fpm.conf

回答1件
あなたの回答
tips
プレビュー