Home Operation and Maintenance Nginx What to do if the nginx.pid file is lost when restarting nginx

What to do if the nginx.pid file is lost when restarting nginx

Oct 19, 2020 pm 05:31 PM
nginx

What to do if the nginx.pid file is lost when restarting nginx

1. Stop operation of nginx

(Recommended tutorial: nginx tutorial)

The stop operation is through the nginx process This is achieved by sending a signal. The specific error message is as follows:

[root@yoodb.com ~]# /usr/local/nginx/sbin/nginx -s reload
nginx: [error] open() “/usr/local/nginx/logs/nginx.pid” failed (2: No such file or directory)
Copy after login

Step 1:

Query the nginx main process number, the code is as follows:

ps -ef | grep nginx
Copy after login

In Find the master process in the process list, and its number is the main process number.

Step 2:

Send a signal to stop Nginx calmly:

kill -QUIT 主进程号
Copy after login

Stop Nginx quickly:

kill -TERM 主进程号
Copy after login

Force to stop Nginx, the code is as follows:

pkill -9 nginx
Copy after login

In addition, if the pid file storage path is configured in nginx.conf, the file will store the Nginx main process ID. If not specified, it will be placed in the nginx logs directory. With the pid file, there is no need to query the main process number of Nginx first, but directly send a signal to Nginx. The command code is as follows:

kill -信号类型 ‘/usr/nginx/logs/nginx.pid’
Copy after login

2. Smooth restart of nginx

If After changing the configuration, you can send a signal to Nginx and restart smoothly.

The smooth restart command code is as follows:

kill -HUP 住进称号或进程号文件路径
Copy after login

Or use

/usr/nginx/sbin/nginx -s reload
Copy after login

Note that after modifying the configuration file, it is best to check whether the modified configuration file is correct to avoid restarting Later, an error occurred in Nginx, which affected the stable operation of the server. The command code to determine whether the Nginx configuration is correct is as follows:

nginx -t -c /usr/nginx/conf/nginx.conf
Copy after login

or

/usr/nginx/sbin/nginx -t
Copy after login

3. Smooth upgrade of nginx

If the server is running Nginx needs to be carried out When upgrading, adding or deleting modules, we need to stop the server and make corresponding modifications, so that the server will stop serving for a period of time. Nginx can perform various upgrade actions without stopping the server without affecting the operation of the server.

Step 1:

If you upgrade the Nginx program, first replace the old program file with the new program. After compiling and installing, the new program will be compiled directly into the Nginx installation directory.

Step 2: Execute the command

kill -USR2 旧版程序的主进程号或进程文件名
Copy after login

At this time, the old Nginx main process will rename its process file to .oldbin, and then execute the new version of Nginx. The new and old Nginx run together to process requests.

At this time, you need to gradually stop the old version of Nginx. Enter the command:

kill -WINCH 旧版主进程号
Copy after login

Slowly the old working process will exit as the task is completed, and the new version of Nginx working process will gradually replace the old version. work process.

You can decide to use the new version or revert to the old version.

4. Start the new/old working process without overloading the configuration

kill -HUP 旧/新版主进程号
Copy after login

Close the old/new process calmly

kill -QUIT 旧/新主进程号
Copy after login

If an error is reported at this time, prompt If there are still processes that have not ended, use the following command to first close the old/new working process, and then close the main process number:

kill -TERM 旧/新工作进程号
Copy after login

Note that on the Alibaba Cloud server, process nginx -s stop and then start again. nginx -s reload always reports an error

nginx: [error] open() “/alidata/server/nginx/logs/nginx.pid” failed (2: No such file or directory)
Copy after login

Cause: the pid is lost after the nginx process is killed, and nginx -s reload cannot be started the next time. Reinstalling can solve the problem. You can also refer to the English explanation:

issued a nginx -s stop and after that 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 do 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)
Copy after login

How to use, the code is as follows:

nginx -c /path/to/config/file
Copy after login

The Linux system execution command is as follows:

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
Copy after login

The above is the detailed content of What to do if the nginx.pid file is lost when restarting nginx. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1656
14
PHP Tutorial
1255
29
C# Tutorial
1229
24
How to configure nginx in Windows How to configure nginx in Windows Apr 14, 2025 pm 12:57 PM

How to configure Nginx in Windows? Install Nginx and create a virtual host configuration. Modify the main configuration file and include the virtual host configuration. Start or reload Nginx. Test the configuration and view the website. Selectively enable SSL and configure SSL certificates. Selectively set the firewall to allow port 80 and 443 traffic.

How to check whether nginx is started How to check whether nginx is started Apr 14, 2025 pm 01:03 PM

How to confirm whether Nginx is started: 1. Use the command line: systemctl status nginx (Linux/Unix), netstat -ano | findstr 80 (Windows); 2. Check whether port 80 is open; 3. Check the Nginx startup message in the system log; 4. Use third-party tools, such as Nagios, Zabbix, and Icinga.

How to check the name of the docker container How to check the name of the docker container Apr 15, 2025 pm 12:21 PM

You can query the Docker container name by following the steps: List all containers (docker ps). Filter the container list (using the grep command). Gets the container name (located in the "NAMES" column).

How to start containers by docker How to start containers by docker Apr 15, 2025 pm 12:27 PM

Docker container startup steps: Pull the container image: Run "docker pull [mirror name]". Create a container: Use "docker create [options] [mirror name] [commands and parameters]". Start the container: Execute "docker start [Container name or ID]". Check container status: Verify that the container is running with "docker ps".

How to create containers for docker How to create containers for docker Apr 15, 2025 pm 12:18 PM

Create a container in Docker: 1. Pull the image: docker pull [mirror name] 2. Create a container: docker run [Options] [mirror name] [Command] 3. Start the container: docker start [Container name]

How to check nginx version How to check nginx version Apr 14, 2025 am 11:57 AM

The methods that can query the Nginx version are: use the nginx -v command; view the version directive in the nginx.conf file; open the Nginx error page and view the page title.

How to configure cloud server domain name in nginx How to configure cloud server domain name in nginx Apr 14, 2025 pm 12:18 PM

How to configure an Nginx domain name on a cloud server: Create an A record pointing to the public IP address of the cloud server. Add virtual host blocks in the Nginx configuration file, specifying the listening port, domain name, and website root directory. Restart Nginx to apply the changes. Access the domain name test configuration. Other notes: Install the SSL certificate to enable HTTPS, ensure that the firewall allows port 80 traffic, and wait for DNS resolution to take effect.

What to do if nginx server is hung What to do if nginx server is hung Apr 14, 2025 am 11:42 AM

When the Nginx server goes down, you can perform the following troubleshooting steps: Check that the nginx process is running. View the error log for error messages. Check the syntax of nginx configuration. Make sure nginx has the permissions you need to access the file. Check file descriptor to open limits. Confirm that nginx is listening on the correct port. Add firewall rules to allow nginx traffic. Check reverse proxy settings, including backend server availability. For further assistance, please contact technical support.

See all articles