nginx报错nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

509 阅读1分钟

错误分析:80端口被占用

解决方案:

安装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

# 增加以下配置
-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

重启防火墙

systemctl restart iptables.service

查看80端口被占用的进程

lsof -i:80

通过kill命令干掉该进程

kill -9 进程号

最后重启nginx即可