0
0

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 5 years have passed since last update.

急にnginxの再起動やコンフィグテストがエラーになった時の対処法

Last updated at Posted at 2020-04-23

本資料の目的

  • nginxの再起動を行う際にエラーが発生した。
  • 別環境でも発生したことがあるので、対応内容をここに整理する。

現象

  • nginxの再起動(configチェック含む)でエラーが発生した。
  • 原因と対処について、ここに整理する。

解決策

事象

  • nginxの再起動やコンフィグテストを行うとエラーが発生する。

原因

  • エラーメッセージより、/var/tmp/nginx配下のディレクトリが存在しないことが原因。
    • なんらかの原因で削除されてしまう為、ある時起動などできなくなる
■Ansible Playbookのエラーメッセージ
TASK [xxx : nginx設定ファイルの文法チェック] **********************************************************
fatal: [xxx]: FAILED! => {"changed": true, "cmd": ["/usr/local/nginx/sbin/nginx", "-t", "-c", "/etc/nginx/nginx.conf"], "delta": "0:00:00.126446", "end": "2020-04-22 12:09:35.651695", "msg": "non-zero return code", "rc": 1, "start": "2020-04-22 12:09:35.525249", "stderr": "nginx: the configuration file /etc/nginx/nginx.conf syntax is ok\nnginx: [emerg] mkdir() \"/var/tmp/nginx/client/\" failed (2: No such file or directory)\nnginx: configuration file /etc/nginx/nginx.conf test failed", "stderr_lines": ["nginx: the configuration file /etc/nginx/nginx.conf syntax is ok", "nginx: [emerg] mkdir() \"/var/tmp/nginx/client/\" failed (2: No such file or directory)", "nginx: configuration file /etc/nginx/nginx.conf test failed"], "stdout": "", "stdout_lines": []}
	to retry, use: --limit @/home/ansible/xxx/xxx.retry

対策

  • 手動で必要なディレクトリを作成する。
/var/tmpへ移動する
# cd /var/tmp

nginxディレクトリが存在しない場合、作成する
# mkdir nginx

nginxディレクトリへ移動する
# cd nginx

client / fcgi / proxyディレクトリが存在しない場合、作成する
# mkdir client fcgi proxy

fcgi / proxyディレクトリのパーミッションを変更する
# chmod 700 fcgi/ proxy/

client / fcgi / proxyディレクトリのオーナーを変更する
# chown nginx:root fcgi/ proxy/ client/

以下のような設定になっていれば完了、コンフィグテストを際実行する
[root@xxx nginx]# ls -ltr
合計 12
drwx------ 2 nginx root 4096  4月 22 12:12 2020 proxy
drwx------ 2 nginx root 4096  4月 22 12:12 2020 fcgi
drwxr-xr-x 2 nginx root 4096  4月 22 12:12 2020 client
[root@xxx nginx]#
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?