我需要重新启动该过程。当我不断看到这些消息时我该怎么办?您需要更多命令吗?
$ 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()
$ service nginx start
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
$ systemctl status nginx.service
● 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 2019-05-29 13:28:29 KST; 26s ago
Process: 24508 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCESS)
Process: 31955 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/FAILURE)
Process: 31952 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 13077 (code=exited, status=0/SUCCESS)
May 29 13:28:27 ip-172-26-12-170 nginx[31955]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
May 29 13:28:27 ip-172-26-12-170 nginx[31955]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
May 29 13:28:28 ip-172-26-12-170 nginx[31955]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
May 29 13:28:28 ip-172-26-12-170 nginx[31955]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
May 29 13:28:29 ip-172-26-12-170 nginx[31955]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
May 29 13:28:29 ip-172-26-12-170 nginx[31955]: nginx: [emerg] still could not bind()
May 29 13:28:29 ip-172-26-12-170 systemd[1]: nginx.service: Control process exited, code=exited status=1
May 29 13:28:29 ip-172-26-12-170 systemd[1]: Failed to start A high performance web server and a reverse proxy server.
May 29 13:28:29 ip-172-26-12-170 systemd[1]: nginx.service: Unit entered failed state.
May 29 13:28:29 ip-172-26-12-170 systemd[1]: nginx.service: Failed with result 'exit-code'.
答案1
当前有一个应用程序正在监听端口80
。很可能是 的另一个实例nginx
。
查找正在监听套接字的应用程序
随着网络状态命令可以找到当前正在监听套接字的应用程序。也可以使用grep过滤 的输出netstat
。
$ netstat -lpn | grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 780/nginx: master p
tcp6 0 0 :::80 :::* LISTEN 780/nginx: master p
列表的最后一项780/nginx
告诉您PID
当前正在监听端口的进程80
。
查找并终止应用程序
和附言可以看到使用socket的进程的进程结构:
$ ps f -g780
PID TTY STAT TIME COMMAND
780 ? Ss 0:00 nginx: master process nginx
781 ? S 0:00 \_ nginx: worker process
782 ? S 0:00 \_ nginx: worker process
783 ? S 0:00 \_ nginx: worker process
784 ? S 0:00 \_ nginx: worker process
785 ? S 0:00 \_ nginx: worker process
786 ? S 0:00 \_ nginx: worker process
787 ? S 0:00 \_ nginx: worker process
788 ? S 0:00 \_ nginx: worker process
随着杀命令现在您可以终止使用套接字的进程:
$ kill 780
如果这不能终止该进程-9
:
$ kill -9 780
然后尝试重新启动您的nginx
服务。
答案2
将来,这里有一些可能会有用的东西。您可以通过运行以下命令来检查 Nginx 配置文件的语法:
nginx -t -c /etc/nginx/nginx.conf
错误输出将提示您问题是什么以及行号。
或者:
使用命令进行调试:
$ 服务 nginx 配置测试
输出类似以下内容:
测试 nginx 配置:nginx:[emerg] /etc/nginx/sites-enabled/nginx_status:11 中未知指令“stub_status”nginx:配置文件 /etc/nginx/nginx.conf 测试失败