A solution to the loss of Nginx.pid after restarting Nginx _nginx

Source: Internet
Author: User

One, Nginx stop operation

The stop operation is achieved by sending a signal to the nginx process.
Step 1: Query Nginx main process number

Copy Code code as follows:

Ps-ef | grep nginx

In the process list, look for the master process, which is numbered as the main process number.

Step 2: Send a signal

Calmly stop Nginx:
Kill-quit Main process Number
Quick Stop Nginx:
Kill-term Main process Number
Force Stop Nginx:

Copy Code code as follows:

Pkill-9 Nginx

In addition, if the nginx.conf configured PID file storage path, the file is stored in the Nginx main process number, if not specified then placed in the Nginx logs directory. With the PID file, we do not need to first query the main process number of the nginx, but directly to the nginx send a signal, the command is as follows:

Copy Code code as follows:

Kill-Signal type '/usr/nginx/logs/nginx.pid '

Second, the smooth restart of the Nginx

If you change the configuration, restart the Nginx, turn off Nginx before you open it? No, you can send a signal to the nginx, smooth reboot.
Smooth Restart command:

Copy Code code as follows:

Kill-hup live in the title or process number file path

or using
/usr/nginx/sbin/nginx-s Reload
Note that after modifying the configuration file, it is best to check that the modified profile is correct so that the Nginx error affects the stable operation of the server after the reboot. Determine if the Nginx configuration is correctly ordered as follows:

Copy Code code as follows:

Nginx-t-c/usr/nginx/conf/nginx.conf
Or
/usr/nginx/sbin/nginx-t

Third, the smooth upgrade of Nginx

If the server is running Nginx to upgrade, add or remove modules, we need to stop the server and make the appropriate changes, so that the server will be stopped for a period of time, Nginx can be non-stop in the case of a variety of upgrade actions without affecting the server running.

Step 1:

If you upgrade the Nginx program, first replace the old program files with a new program, compile and install the new program directly into the Nginx installation directory.

Step 2: Execute the command

KILL-USR2 The main process number or process file name of the legacy program

At this point the old Nginx main process will rename its process file to. oldbin, and then execute the new Nginx. The old and new Nginx conjunction with City run together to handle the request.
To gradually stop the old version of Nginx, enter the command:

Kill-winch Old Moderator Process number

The slowly old work process will exit as the task executes, and the new Nginx work process gradually replaces the old version of the work process.
You can decide whether to use the new version or revert to the old version.

Four, do not overload the configuration start new/old worker processes

Kill-hup old/New main process number
Calmly close the old/new process
Kill-quit old/New main process number
If you have an error at this point, you are prompted to close the old/new worker process with the following command, and then close the main process number:
Kill-term old/New worker process number

In this way, if you want to revert to the old version, only a few of the above steps are to operate the new main process number, if you want to use the new version of the above several steps to operate the old moderator process number on the line.

The above is nginx some basic operations, hope that Nginx can have a better way to handle these operations, preferably nginx command rather than send the system signal to Nginx process.

On the Aliyun server, the nginx-s reload is restarted after the process nginx-s stop, always reporting an error Nginx: [ERROR] Open () "/alidata/server/nginx/logs/nginx.pid" Failed (2:no such file or directory).
Reason: Nginx process after the loss of PID, the next time you open the Nginx-s reload can not start, reload to solve the problem, do not do, you decide, haha.

Or the English explanation is more professional:

issued a nginx-s stop and after the I got this error when trying to reload it.
[ERROR]: Invalid PID number "" In "/var/run/nginx.pid"
That/var/run/nginx/pid file is empty ATM.
What do I need to does to fix it?

Nginx-s Reload is only used to tell-a running nginx process to reload its config. After a stop, you don ' t have a running nginx process to send a signal to. Just Run Nginx (possibly with a-c/path/to/config/file)

How to use:

Copy Code code as follows:

Nginx-c/path/to/config/file
My machine is like this:/alidata/server/nginx/sbin/nginx-c/alidata/server/nginx/conf/nginx.conf

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.