PHPのバージョンアップしたら、Nginxが起動しなくなった

Ubuntu 18.04で、PHPをPHP7.2からPHP7.4にアップデートしたところ、作業後にOSを再起動したら、Nginxが起動しなくなった。原因を調べて対処したので、メモを残す。

Nginxのステータスを確認したところ。

ubuntu@ip-10-0-0-122:/etc/nginx$ sudo service nginx status
● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Wed 2020-10-14 22:35:23 PDT; 5s ago
     Docs: man:nginx(8)
  Process: 1296 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)
Oct 14 22:35:23 ip-10-0-0-122 systemd[1]: Starting A high performance web server and a reverse proxy server...
Oct 14 22:35:23 ip-10-0-0-122 nginx[1296]: nginx: [emerg] "try_files" directive is duplicate in /etc/nginx/sites-enabled
Oct 14 22:35:23 ip-10-0-0-122 nginx[1296]: nginx: configuration file /etc/nginx/nginx.conf test failed
Oct 14 22:35:23 ip-10-0-0-122 systemd[1]: nginx.service: Control process exited, code=exited status=1
Oct 14 22:35:23 ip-10-0-0-122 systemd[1]: nginx.service: Failed with result 'exit-code'.
Oct 14 22:35:23 ip-10-0-0-122 systemd[1]: Failed to start A high performance web server and a reverse proxy server.
ubuntu@ip-10-0-0-122:/etc/nginx$

PHP7.4にアップデートしたタイミングで、Apacheがインストールされて、これが自動起動しており、Nginxと、ポート80の使用が競合して、Nginxが落ちていた。apache2の自動起動を停止する。

sudo systemctl disable apache2

それでも、まだ、Nginxの起動でエラーになる。ログを見ると、コンフィグの問題のようなので、configtestを実施し、見事にエラーになる。

ubuntu@ip-10-0-0-122:/etc/nginx/sites-available$ sudo service nginx configtest
 * Testing nginx configuration                                                                                   [fail]
ubuntu@ip-10-0-0-122:/etc/nginx/sites-available$

Nginxのコンフィグのdefaultで、php7.2-fpmの部分を、php7.4-fpmのsockに書き換え。

その後、Nginxの起動を試すが失敗。Nginxのコンフィグチェックを行って、エラーになっている行を特定。

sudo nginx -t
nginx: [emerg] "try_files" directive is duplicate in /etc/nginx/sites-enabled/default:77
nginx: configuration file /etc/nginx/nginx.conf test failed

“try_files” がダブっているというので、場所を確認して、変更した。なぜ、急にエラーになったのか、はあるが、とりあえず、スルー。修正後は、Nginxが無事に起動した。

最初のStatusのログをみると、最初から”try_files ”が問題って書いてあった。おちついて、見る必要あり。

スポンサーリンク

シェアする

  • このエントリーをはてなブックマークに追加

フォローする