foreword
After receiving the command, the Nginx service of the server needs to be restarted.
But the direct execution sudo nginx -s reload
fails to display
invalid PID number “” in “/run/nginx.pid” 与(98: Address already in use)
Investigate and try to resolve this
Phase 1, execute sudo nginx -c /etc/nginx/nginx.conf
Analysis of the fault name shows that this is an error reported by nginx when reloading the configuration file, so it is necessary to check whether the configuration file is feasible.
Run first:
sudo nginx -t -c /etc/nginx/nginx.conf
Determine whether the configuration file is basically normal.
run if passsudo nginx -c /etc/nginx/nginx.conf
Under normal circumstances, this is fine, but if an Nginx process occupies the port before due to interference from some factors, it will cause an error message similar to the following:
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
Phase 2: Close the process sudo kill -QUIT XXX
invalid operation
Will consider closing the process that occupies the port, but this isInvalid
If you really want to do this, the process is as follows:
The prompt is occupying port 443, but the result that does not contain the PID is seen directly with netstat -lnp|grep 443
the command :
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN -
need to usesudo netstat -lnp|grep 443
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 1321/nginx: The worker
knows that the occupied port is 1321
followed by executionsudo kill 1321
But if you continue to observe, you will find that this process will restart because the key process has not been closed
correct operation
Execute ps -ef | grep nginx
to get the master process PID:
root 2650 1 0 Jun30 ? 00:00:00 nginx: master process nginx -c /etc/nginx/nginx.conf
implementsudo kill -QUIT 2650
After waiting for a few minutes, use · ps -ef | grep nginx
to check whether it is closed. If there is no master, it means that the Nginx service is stopped and can be restarted. The
startup process is running sudo nginx -c /etc/nginx/nginx.conf
.
Afterwards, you can use to ps -ef | grep nginx
check whether it is started
epilogue
mission completed. (~ ̄▽ ̄)~