> 服务器 >

nginx启动提示nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

来源:网络 文章列表 2022-01-17 8
nginx端口占用解决方案,当然如果已经安装了iptables,可以把占用端口号的那个进程杀死,然后启动Nginx

今天在centos7部署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默认启动端口是80,之前刚好在这个服务器启动了个80端口的tomcat。现解决方式如下:

安装iptables服务

需要通过防火墙开放对外端口。如果服务器上没有iptables服务,需要安装。如果有,则跳过。

yum install iptables-services
systemctl mask firewalld.service
systemctl enable iptables.service
systemctl enable ip6tables.service

 

配置端口

进入iptables配置80端口,因为nginx默认是由80端口访问

vi /etc/sysconfig/iptables

打开后,默认的配置信息如下(加粗部分为新添加的):
INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [6:696]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT

-A INPUT -p tcp -m state --state NEW -m tcp --dport 21 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT

A INPUT -p tcp -m state --state NEW -m tcp --dport 30000:30999 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

后续需要开放其它端口,也是在此文件中添加修改即可!

修改完后,保存退出文件编辑。

:wq

重启防火墙

systemctl restart iptables.service
  • 1

查看80端口被占用的进程

lsof -i:80
  • 1

通过kill命令干掉该进程

kill -9 进程号

 

启动nginx

这个时候在启动nginx,一切正常了!

/usr/local/nginx/sbin/nginx

 

 

 

腾讯云限量秒杀

1核2G 5M 50元/年 2核4G 8M 74元/年 4核8G 5M 818元/年 CDN流量包 100GB 9元

版权声明

本站部分原创文章,部分文章整理自网络。如有转载的文章侵犯了您的版权,请联系站长删除处理。如果您有优质文章,欢迎发稿给我们!联系站长:
愿本站的内容能为您的学习、工作带来绵薄之力。

评论

  • 随机获取
点击刷新
精彩评论

友情链接