【Nginx】重启报错,端口重复占用无法解决

 

问题叙述:nginx不能使用重启命令

  • 在操练过程中遇到了一个nginx重启命令的错误,就是不能重启,杀掉可以正常启动,更改配置文件后想重启就出现错误,开始以为是配置文件的问题,去除新增的配置文件依旧重启错误,关闭启动也不行,多次尝试后用一下方法解决。

错误展示:

[root@localhost ~]# systemctl restart nginx			# 重启服务时出现错误
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.

错误日志如下:

-- Unit nginx.service has begun starting up.
2月 14 19:42:07 localhost.localdomain nginx[18394]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
2月 14 19:42:07 localhost.localdomain nginx[18394]: nginx: configuration file /etc/nginx/nginx.conf test is successful
2月 14 19:42:07 localhost.localdomain nginx[18397]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
2月 14 19:42:07 localhost.localdomain nginx[18397]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
2月 14 19:42:08 localhost.localdomain nginx[18397]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
2月 14 19:42:08 localhost.localdomain nginx[18397]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
2月 14 19:42:08 localhost.localdomain nginx[18397]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
2月 14 19:42:08 localhost.localdomain nginx[18397]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
2月 14 19:42:09 localhost.localdomain nginx[18397]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
2月 14 19:42:09 localhost.localdomain nginx[18397]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
2月 14 19:42:09 localhost.localdomain nginx[18397]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
2月 14 19:42:09 localhost.localdomain nginx[18397]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
2月 14 19:42:10 localhost.localdomain nginx[18397]: nginx: [emerg] still could not bind()
2月 14 19:42:10 localhost.localdomain systemd[1]: nginx.service: control process exited, code=exited status=1
2月 14 19:42:10 localhost.localdomain systemd[1]: Failed to start The nginx HTTP and reverse proxy server.

查看80端口:

[root@localhost ~]# lsof -i:80					# 查看80端口
COMMAND   PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
nginx   21843  root    6u  IPv4  82928      0t0  TCP *:http (LISTEN)
nginx   21843  root    7u  IPv6  82929      0t0  TCP *:http (LISTEN)
nginx   21844 nginx    6u  IPv4  82928      0t0  TCP *:http (LISTEN)
nginx   21844 nginx    7u  IPv6  82929      0t0  TCP *:http (LISTEN)
nginx   21845 nginx    6u  IPv4  82928      0t0  TCP *:http (LISTEN)
nginx   21845 nginx    7u  IPv6  82929      0t0  TCP *:http (LISTEN)

尝试pkill杀死进程:

[root@localhost ~]# pkill -9 nginx 				# 杀掉进程
[root@localhost ~]# netstat -tnlp				# 查看进程
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      1551/php-fpm: maste 
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      1805/mysqld         
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      973/sshd            
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1055/master         
tcp6       0      0 :::22                   :::*                    LISTEN      973/sshd            
tcp6       0      0 ::1:25                  :::*                    LISTEN      1055/master         
[root@localhost html]# nginx					# 启动nginx
[root@localhost html]# netstat -tnlp			# 查看进程
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      1551/php-fpm: maste 
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      1805/mysqld         
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      21843/nginx: master 
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      973/sshd            
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1055/master         
tcp6       0      0 :::80                   :::*                    LISTEN      21843/nginx: master 
tcp6       0      0 :::22                   :::*                    LISTEN      973/sshd            
tcp6       0      0 ::1:25                  :::*                    LISTEN      1055/master         
[root@localhost html]# lsof -i:80				# 查看端口
COMMAND   PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
nginx   21843  root    6u  IPv4  82928      0t0  TCP *:http (LISTEN)
nginx   21843  root    7u  IPv6  82929      0t0  TCP *:http (LISTEN)
nginx   21844 nginx    6u  IPv4  82928      0t0  TCP *:http (LISTEN)
nginx   21844 nginx    7u  IPv6  82929      0t0  TCP *:http (LISTEN)
nginx   21845 nginx    6u  IPv4  82928      0t0  TCP *:http (LISTEN)
nginx   21845 nginx    7u  IPv6  82929      0t0  TCP *:http (LISTEN)
[root@localhost html]# systemctl restart 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 ~]# yum install -y psmisc		# 安装应用
[root@localhost ~]# fuser -k 80/tcp  			# 杀死进程
80/tcp:              21843 21844 21845
[root@localhost ~]# systemctl start nginx		# 启动成功

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值