0

CentOS7、nginx、php-fpmの構成を組み立てる途中で、nginxの再起動の際にエラーが出ています。

[root@localhost www]# systemctl start nginx
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.

[root@localhost www]# sudo systemctl -l status nginx.service
● nginx.service - nginx - high performance web server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since 木 2020-08-13 15:42:14 JST; 5s ago
     Docs: http://nginx.org/en/docs/
  Process: 2591 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=1/FAILURE)

 8月 13 15:42:11 localhost nginx[2591]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
 8月 13 15:42:12 localhost nginx[2591]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
 8月 13 15:42:12 localhost nginx[2591]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
 8月 13 15:42:13 localhost nginx[2591]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
 8月 13 15:42:13 localhost nginx[2591]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
 8月 13 15:42:14 localhost nginx[2591]: nginx: [emerg] still could not bind()
 8月 13 15:42:14 localhost systemd[1]: nginx.service: control process exited, code=exited status=1
 8月 13 15:42:14 localhost systemd[1]: Failed to start nginx - high performance web server.
 8月 13 15:42:14 localhost systemd[1]: Unit nginx.service entered failed state.
 8月 13 15:42:14 localhost systemd[1]: nginx.service failed.

[root@localhost www]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

エラーメッセージなどで検索してみましたが、解決には至らずこちらにまいりました。

目標は展開したソースにブラウザアクセスして開けるまでです、よろしくお願いいたします。

1 件の回答 1

3

以下のエラーメッセージに注目すると、"ポート 80 が既に使用されている" と出ています。

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

何らかの理由で古い nginx のプロセスが 80 番ポートを掴んだままになっている可能性があるので、
例えば lsof コマンドなどで該当のプロセスを突き止めます。

実行例: ポート ":80" を使用しているプロセスを一覧表示

$ sudo lsof -i :80
nginx    3254     root    6u  IPv4  20710      0t0  TCP *:http (LISTEN)
nginx    3255    nginx    6u  IPv4  20710      0t0  TCP *:http (LISTEN)

何か結果が表示され、nginx に関するものであれば手動でそれらのプロセスを kill してください。

$ sudo kill -9 3254 3255

もしくは、手っ取り早くOSを一旦再起動してみるのも一つの方法です。

参考:
他のプロセスがポートを占有してnginxを再起動できない - Qiita

1
  • 調べたらapacheが占領していたのでアンインストールしたら、解決しました。感謝します。 2020年8月13日 7:27

この質問に回答するには、ログインする必要があります。

求めていた回答ではありませんか? のタグが付いた他の質問を参照する。