nginx start, restart, shut down commands
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 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
nginx -t -c /usr/nginx/conf/nginx.conf
or
/usr/nginx/sbin/nginx -tSmooth 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.

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











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.

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

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

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]

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

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.
