Home Backend Development PHP Tutorial nginx start, restart, shut down commands

nginx start, restart, shut down commands

Aug 08, 2016 am 09:32 AM
conf kill nginx usr

nginx startup command is:

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

-c specifies the path to the configuration file. Without -nginx, it will automatically Load the configuration file from the default path.


After studying the nginx help document, I found that there is the -s parameter to manage the nginx service:
# /usr/local/nginx/sbin/nginx -h
nginx version: nginx/0.7.63
Usage : nginx [-?hvVt] [-s signal] [-c filename] [-p prefix] [-g directives]

Options:
-?,-h : this help
-v : show version and exit
- V : show version and configure options then exit
-t : test configuration and exit
-s signal : send signal to a master process: stop, quit, reopen, reload
-p prefix : set prefix path (default: / usr/local/nginx/)
-c filename: set configuration file (default: conf/nginx.conf)
-g directives: set global directives out of configuration file

So execute
# /usr/local/nginx/sbin /nginx -s reload
nginx has been restarted successfully

The following is the reproduced content

nginx startup, restart, shutdown commands

Stop operation
Stop operation is by sending a signal to the nginx process (what is a signal please (See linux article)
Step 1: Query the nginx main process number
ps -ef | grep nginx
Look for the master process in the process list, and its number is the main process number.
Step 2: Send signal
Stop Nginx gracefully:
kill -QUIT main process number
Quickly stop Nginx:
kill -TERM main process number
Force stop Nginx:
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, we don’t need to query the main process number of Nginx first, but directly send a signal to Nginx. The command is as follows:
kill -Signal type '/usr/nginx/logs/nginx.pid'
Smooth restart
If you change the configuration, you need to restart Nginx. Do you need to close Nginx first and then open it? No, you can send a signal to Nginx to restart smoothly.
Smooth restart command:
kill -HUP Enter the name or process number file path

or use

/usr/nginx/sbin/nginx -s reload

Note that after modifying the configuration file, the last It is best to check whether the modified configuration file is correct first, so as to avoid errors in Nginx after restarting, which will affect the stable operation of the server. The command 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

Smooth upgrade
if When the Nginx running on the server wants to upgrade, add or delete modules, we need to stop the server and make corresponding modifications. In this way, the server will stop serving for a period of time. Nginx can perform various upgrade actions without shutting down. Does not affect server operation.
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 The main process number or process file name of the old version of the program
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 old moderator process number
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 of the working process. .
At this point, we can decide to use the new version or revert to the old version.
Start the new/old worker process without overloading the configuration
kill -HUP the old/new moderator process number
Close the old/new process calmly
kill -QUIT the old/new main process number
If an error is reported at this time, it will prompt whether there are any processes When finished, use the following command to first close the old/new working process, and then close the main process ID:
kill -TERM old/new working process ID
In this way, if you want to restore to the old version, you only need to follow the above steps The new moderator process ID. If you want to use the new version, just follow the above steps to the old moderator process ID.
The above are some basic operations of Nginx. I hope Nginx can have a better way to handle these operations in the future. It is best to use Nginx commands instead of sending system signals to the Nginx process.

The above introduces the nginx startup, restart, and shutdown commands, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

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)

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 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.

How to check whether nginx is started? How to check whether nginx is started? Apr 14, 2025 pm 12:48 PM

In Linux, use the following command to check whether Nginx is started: systemctl status nginx judges based on the command output: If "Active: active (running)" is displayed, Nginx is started. If "Active: inactive (dead)" is displayed, Nginx is stopped.

How to start nginx server How to start nginx server Apr 14, 2025 pm 12:27 PM

Starting an Nginx server requires different steps according to different operating systems: Linux/Unix system: Install the Nginx package (for example, using apt-get or yum). Use systemctl to start an Nginx service (for example, sudo systemctl start nginx). Windows system: Download and install Windows binary files. Start Nginx using the nginx.exe executable (for example, nginx.exe -c conf\nginx.conf). No matter which operating system you use, you can access the server IP

How to start nginx in Linux How to start nginx in Linux Apr 14, 2025 pm 12:51 PM

Steps to start Nginx in Linux: Check whether Nginx is installed. Use systemctl start nginx to start the Nginx service. Use systemctl enable nginx to enable automatic startup of Nginx at system startup. Use systemctl status nginx to verify that the startup is successful. Visit http://localhost in a web browser to view the default welcome page.

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 solve nginx403 How to solve nginx403 Apr 14, 2025 am 10:33 AM

How to fix Nginx 403 Forbidden error? Check file or directory permissions; 2. Check .htaccess file; 3. Check Nginx configuration file; 4. Restart Nginx. Other possible causes include firewall rules, SELinux settings, or application issues.

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.

See all articles