As shown in the figure:
Check the port occupancy:
sudo netstat -apn | grep 80
Check the process occupying the port:
ps -ef | grep 3345
It can be seen from the results that port 80 is occupied by nginx itself. You can kill the process and restart nginx
sudo kill -9 3345
##sudo netstat - apn | grep 80
The following describes how to start, stop and restart nginx
Start
Startup code format: nginx installation directory address -c nginx configuration file addressFor example:[root@linuxserver sbin]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
Stop
There are three ways to stop nginx: Easy stop 1. Check the process number[root@linuxserver ~]# ps -ef|grep nginx
[root@linuxserver ~]# kill -quit 2072
1. Check the process number
[root@linuxserver ~]# ps -ef|grep nginx
2. Kill the process
[root@linuxserver ~]# kill -term 2132 或 [root@linuxserver ~]# kill -int 2132
Force stop
[root@linuxserver ~]# pkill -9 nginx
Restart
1. Verify whether the nginx configuration file is correct
Method 1: Enter the nginx installation directory sbin and enter the command ./nginx -t
See the following display nginx.conf syntax is ok
nginx. conf test is successful means the configuration file is correct!
Method 2: Add -t before the start command -c
2. Restart the nginx service. Method 1: Enter the nginx executable directory sbin and enter the command ./nginx -s reload
Method 2: Find the current nginx process number, and then enter the command: kill -hup process No. to restart nginx service
The above is the detailed content of How to solve the problem that the port is occupied when opening Nginx. For more information, please follow other related articles on the PHP Chinese website!