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)
Step 1:
Query the nginx main process number, the code is as follows:
ps -ef | grep nginx
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 主进程号
Stop Nginx quickly:
kill -TERM 主进程号
Force to stop Nginx, the code is as follows:
pkill -9 nginx
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’
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 住进称号或进程号文件路径
Or use
/usr/nginx/sbin/nginx -s reload
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
or
/usr/nginx/sbin/nginx -t
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 旧版程序的主进程号或进程文件名
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 旧版主进程号
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 旧/新版主进程号
Close the old/new process calmly
kill -QUIT 旧/新主进程号
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 旧/新工作进程号
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)
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)
How to use, the code is as follows:
nginx -c /path/to/config/file
The Linux system execution command is as follows:
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
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!

NGINX initially solved the C10K problem and has now developed into an all-rounder who handles load balancing, reverse proxying and API gateways. 1) It is well-known for event-driven and non-blocking architectures and is suitable for high concurrency. 2) NGINX can be used as an HTTP and reverse proxy server, supporting IMAP/POP3. 3) Its working principle is based on event-driven and asynchronous I/O models, improving performance. 4) Basic usage includes configuring virtual hosts and load balancing, and advanced usage involves complex load balancing and caching strategies. 5) Common errors include configuration syntax errors and permission issues, and debugging skills include using nginx-t command and stub_status module. 6) Performance optimization suggestions include adjusting worker parameters, using gzip compression and

Diagnosis and solutions for common errors of Nginx include: 1. View log files, 2. Adjust configuration files, 3. Optimize performance. By analyzing logs, adjusting timeout settings and optimizing cache and load balancing, errors such as 404, 502, 504 can be effectively resolved to improve website stability and performance.

NGINXUnitischosenfordeployingapplicationsduetoitsflexibility,easeofuse,andabilitytohandledynamicapplications.1)ItsupportsmultipleprogramminglanguageslikePython,PHP,Node.js,andJava.2)Itallowsdynamicreconfigurationwithoutdowntime.3)ItusesJSONforconfigu

NGINX can be used to serve files and manage traffic. 1) Configure NGINX service static files: define the listening port and file directory. 2) Implement load balancing and traffic management: Use upstream module and cache policies to optimize performance.

NGINX is suitable for handling high concurrency and static content, while Apache is suitable for dynamic content and complex URL rewrites. 1.NGINX adopts an event-driven model, suitable for high concurrency. 2. Apache uses process or thread model, which is suitable for dynamic content. 3. NGINX configuration is simple, Apache configuration is complex but more flexible.

NGINX and Apache each have their own advantages, and the choice depends on the specific needs. 1.NGINX is suitable for high concurrency, with simple deployment, and configuration examples include virtual hosts and reverse proxy. 2. Apache is suitable for complex configurations and is equally simple to deploy. Configuration examples include virtual hosts and URL rewrites.

The purpose of NGINXUnit is to simplify the deployment and management of web applications. Its advantages include: 1) Supports multiple programming languages, such as Python, PHP, Go, Java and Node.js; 2) Provides dynamic configuration and automatic reloading functions; 3) manages application lifecycle through a unified API; 4) Adopt an asynchronous I/O model to support high concurrency and load balancing.

NGINX started in 2002 and was developed by IgorSysoev to solve the C10k problem. 1.NGINX is a high-performance web server, an event-driven asynchronous architecture, suitable for high concurrency. 2. Provide advanced functions such as reverse proxy, load balancing and caching to improve system performance and reliability. 3. Optimization techniques include adjusting the number of worker processes, enabling Gzip compression, using HTTP/2 and security configuration.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
