41
38

More than 5 years have passed since last update.

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

Posted at

現象

nginxを起動しようとすると、Address already in useと言われ再起動できない。

$ sudo /usr/sbin/nginx
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()

環境

$ nginx -v
nginx version: nginx/1.12.2

原因

nginxが異常終了する等して古いhttpdプロセスが残っていることが原因。

対策

lsofコマンドで古いプロセスを表示し、killすればよい。

$ sudo lsof -i | grep nginx
nginx    3254     root    6u  IPv4  20710      0t0  TCP *:http (LISTEN)
nginx    3254     root    7u  IPv6  20711      0t0  TCP *:http (LISTEN)
nginx    3255    nginx    6u  IPv4  20710      0t0  TCP *:http (LISTEN)
nginx    3255    nginx    7u  IPv6  20711      0t0  TCP *:http (LISTEN)
nginx    7013     root    6u  IPv4 227085      0t0  TCP *:vcom-tunnel (LISTEN)
nginx    7014    nginx    6u  IPv4 227085      0t0  TCP *:vcom-tunnel (LISTEN)

3254,3255,7013,7014のidをもつプロセスが残っていることが分かる。

$ sudo kill -9 3254
$ sudo kill -9 3255
$ sudo kill -9 7013
$ sudo kill -9 7014

これで起動するようになる。

41
38
2

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
41
38