1、nginx -t #Nginx配置文件检查

上述截图代表检查没问题

上述截图检查配置文件配置错误,并提示错误文件位置
2、systemctl restart nginx #重启Nginx

重启Nginx失败
3、systemctl status nginx.service #查看Nginx服务状态

80端口被占导致服务启动失败
4、netstat -nap|grep 80 #查看80端口被占用情况

kill -9 4013199 #杀掉占用进程,再次复查直到没有
Centos7默认没有netstat,没有需要安装
yum install -y net-tools #安装net-tools
netstat -nap|gerp 4045574 #根据PID查看端口

ps 4045574 #查看进程详细信息

5、systemctl start nginx #nginx启动成功

6、ps aux|grep nginx / ps -ef|grep nginx 查看Nginx

7、netstat -ntlp #查看端口占用情况

8、netstat -tuln|grep 9000 #查看端口是否被占用

9、sudo yum install firewalld #安装防火墙
10、sudo systemctl status firewalld #检查防火墙服务状态

上图 防火墙正常启用中,下图为未启用

firewall-cmd --state #查看防火墙状态

11、sudo systemctl stop firewalld #关闭防火墙
12、sudo systemctl disable firewalld #永久关闭防火墙 重启也不会开启
13、sudo systemctl start firewalld #打开防火墙
14、sudo systemctl enable firewalld #开机自动启动防火墙
15、sudo firewall-cmd --zone=public --add-port=8080/tcp --permanent #开放指定端口通过防火 墙
sudo firewall-cmd --zone=public --remove-port=8080/tcp --permanent
--permanent 表示永久开放,不加的话就是临时
16、sudo firewall-cmd --reload #开放端口命令执行后重载防火墙,使开放端口命令生效


17、sudo firewall-cmd --zone=public --query-port=8080/tcp #查看端口是否开放

代表防火墙未开启

端口8080未允许通过防火墙
18、sudo firewall-cmd --list-all #查看防火墙规则
