15
21

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

NGINX エラーログをみて解決する

Last updated at Posted at 2021-02-15

はじめに

awsのec2内で作業をしています

ログをみる

mginxをスタートできないから、ログを見た

[.ssh]$ systemctl status nginx

(これ赤丸→)● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since 土 2021-02-13 00:19:36 UTC; 8h ago

別のコマンドでログを見た01

[ ~]$ nginx -t

nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)
2021/02/15 02:13:57 [warn] 24494#0: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:5
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
2021/02/15 02:13:57 [emerg] 24494#0: open() "/run/nginx.pid" failed (13: Permission denied)
nginx: configuration file /etc/nginx/nginx.conf test failed

別のコマンドでログを見た02

$ sudo nano /var/log/nginx/error.log

2021/02/15 02:13:05 [emerg] 24485
#0: open() "/var/www/rails/myapp/current/log/nginx.error.log" 
faile(2: No such file or directory)

別のコマンドでログを見た03

nginx -t -c /etc/nginx/nginx.conf

nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)
2021/02/15 02:24:20 [warn] 24813#0: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:5
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
2021/02/15 02:24:20 [emerg] 24813#0: open() "/run/nginx.pid" failed (13: Permission denied)
nginx: configuration file /etc/nginx/nginx.conf test failed

別のコマンドでログを見た04

% sudo nginx -t

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: [emerg] open() "/var/www/rails/myapp/current/log/nginx.error.log" failed (2: No such file or directory)
nginx: configuration file /etc/nginx/nginx.conf test failed

大事なのこれっぽい

"/var/www/rails/myapp/current/log/nginx.error.log" failed (2: No such file or directory)

上記が書かれているファイルに行き、コメントアウトしてみる
/etc/nginx/nginx.conf/myapp.conf

myapp.conf
#各種ログのディレクトリ設定
#error_log  /var/www/rails/myapp/current/log/nginx.error.log debug;
#access_log /var/www/rails/myapp/current/log/nginx.access.log;
・
・
省略


ログを再びみる&startさせてみる

[~]$ sudo service nginx start

Redirecting to /bin/systemctl start nginx.service

[~]$ systemctl status nginx.service

(緑の丸に変わった!)● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: active (running) since 月 2021-02-15 03:57:17 UTC; 34s ago
  Process: 26523 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 26520 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 26519 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 26526 (nginx)
   CGroup: /system.slice/nginx.service
           ├─26526 nginx: master process /usr/sbin/nginx
           └─26527 nginx: worker process

解決できた

まとめ

エラーログのコマンドまとめ

$ systemctl status nginx
$ nginx -t
$ sudo nano /var/log/nginx/error.log
$ nginx -t -c /etc/nginx/nginx.conf
$ sudo nginx -t

参考
https://stackoverflow.com/questions/35868976/nginx-job-for-nginx-service-failed-because-the-control-process-exited/51684856#51684856

15
21
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
21

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?