centos服务器搭建QA-启动nginx时提示端口被占用

本文介绍在CentOS环境下启动Nginx时遇到端口80被HTTPD占用的问题,提供了解决方案,包括如何检查端口占用状态、停止HTTPD服务以及重启Nginx。

启动nginx时报错-提示端口被占用

在centos搭建服务器时遇到systemctl start nginx时提示ob for nginx.service failed

查看httpd占用状态

在使用centos搭建httpd服务环境时先行启动了httpd导致了服务器端口80 被占用如下

[root@centos conf.d]# netstat -apn|grep :80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      10300/httpd

这里可以看出来80端口已经被httpd占用

启动nginx服务

[root@centos]# 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.

此时开启nginx已经提示错误,使用命令来查看该服务的状态

[root@centos]# systemctl status nginx.service 
● nginx.service - nginx - high performance web server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Sun 2020-04-19 11:06:44 CST; 10s ago
     Docs: http://nginx.org/en/docs/
  Process: 11066 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=1/FAILURE)

Apr 19 11:06:41 centos systemd[1]: Starting nginx - high performance web server...
Apr 19 11:06:42 centos nginx[11066]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 19 11:06:42 centos nginx[11066]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 19 11:06:43 centos nginx[11066]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 19 11:06:43 centos nginx[11066]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 19 11:06:44 centos nginx[11066]: nginx: [emerg] still could not bind()
Apr 19 11:06:44 centos systemd[1]: nginx.service: control process exited, code=exited status=1
Apr 19 11:06:44 centos systemd[1]: Failed to start nginx - high performance web server.
Apr 19 11:06:44 centos systemd[1]: Unit nginx.service entered failed state.
Apr 19 11:06:44 centos systemd[1]: nginx.service failed.

以上信息可以看出该服务的端口80被占用所以导致nginx无法启动,此时我们需要将上方的httpd给关闭,然后再次启用nginx

[root@centos conf.d]# service httpd stop 
Redirecting to /bin/systemctl stop httpd.service

启动nginx

[root@centos conf.d]# systemctl restart nginx.service
[root@centos conf.d]# systemctl status nginx.service
● nginx.service - nginx - high performance web server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: active (running) since Sun 2020-04-19 11:21:46 CST; 15min ago
     Docs: http://nginx.org/en/docs/
  Process: 13715 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
 Main PID: 13716 (nginx)

注意,文中的“centos”为类linux的操作系统,需有一定基础的童鞋操作。

总结

之所以出现此类错误,是由于小编手动重启httpd服务,而不是先重启nginx导致

推荐阅读

欢迎关注我的公众号“魔搜索”,原创技术/资源/活动文章先行推送。

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值