解决启动nginx时报错“Job for nginx.service failed because the control process exited with error code”
- 在安装完nginx时启动
[root@qmfz nginx]# 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@qmfz nginx]# 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服务情况
[root@qmfz nginx]# systemctl status nginx.service
● nginx.service
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since 三 2021-01-20 12:22:58 CST; 1min 12s ago
Process: 13931 ExecStart=/usr/local/nginx/sbin/nginx (code=exited, status=1/FAILURE)
1月 20 12:22:56 qmfz nginx[13931]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Add...se)
1月 20 12:22:56 qmfz nginx[13931]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Add...se)
1月 20 12:22:57 qmfz nginx[13931]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Add...se)
1月 20 12:22:57 qmfz nginx[13931]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Add...se)
1月 20 12:22:58 qmfz nginx[13931]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Add...se)
1月 20 12:22:58 qmfz nginx[13931]: nginx: [emerg] still could not bind()
1月 20 12:22:58 qmfz systemd[1]: nginx.service: control process exited, code=exited status=1
1月 20 12:22:58 qmfz systemd[1]: Failed to start nginx.service.
1月 20 12:22:58 qmfz systemd[1]: Unit nginx.service entered failed state.
1月 20 12:22:58 qmfz systemd[1]: nginx.service failed.
Hint: Some lines were ellipsized, use -l to show in full.
- (98: Add…se)端口已被占用,我们看看是被什么占用了
[root@qmfz nginx]# netstat -apn|grep :80
tcp 0 0 192.168.10.140:53002 14.17.102.87:80 TIME_WAIT -
tcp6 0 0 127.0.0.1:8005 :::* LISTEN 2450/java
tcp6 0 0 :::8009 :::* LISTEN 2450/java
tcp6 0 0 :::8080 :::* LISTEN 2450/java
tcp6 0 0 :::80 :::* LISTEN 987/httpd
PS:没有netstat这个命令,可以使用yum install net-tools安装。
- 我们可以看出是被httpd占用了80端口,可以停止该服务或者更改nginx的端口。
[root@qmfz nginx]# service httpd stop
Redirecting to /bin/systemctl stop httpd.service
- 最后启动nginx就可以了