Nginx Daily Maintenance Common commands _nginx

Source: Internet
Author: User
Tags openssl

First, concise nginx common commands

1. Start Nginx

Copy Code code as follows:
Poechant@ubuntu:sudo./sbin/nginx

2. Stop Nginx
Copy Code code as follows:
Poechant@ubuntu:sudo./sbin/nginx-s Stop
Poechant@ubuntu:sudo./sbin/nginx-s quit

-S is the way to send signals to the Nginx.

3. Nginx Overload Configuration

Copy Code code as follows:

Poechant@ubuntu:sudo./sbin/nginx-s Reload

The above is the way to send a signal to the Nginx, or use:
Copy Code code as follows:

Poechant@ubuntu:service Nginx Reload

4. Specify the configuration file
Copy Code code as follows:
Poechant@ubuntu:sudo./sbin/nginx-c/usr/local/nginx/conf/nginx.conf

-C indicates configuration, specifying the configuration file.

5. View Nginx Version
There are two parameters that can view the version information of the Nginx. The first of these is as follows:

Copy Code code as follows:

poechant@ubuntu:/usr/local/nginx$./sbin/nginx-v
Nginx:nginx version:nginx/1.0.0

The other shows detailed version information:
Copy Code code as follows:

poechant@ubuntu:/usr/local/nginx$./sbin/nginx-v
Nginx:nginx version:nginx/1.0.0
Nginx:built by GCC 4.3.3 (Ubuntu 4.3.3-5ubuntu4)
NGINX:TLS SNI Support Enabled
Nginx:configure arguments:--with-http_ssl_module--with-openssl=/home/luming/openssl-1.0.0d/

6. Check that the configuration file is correct
Copy Code code as follows:
poechant@ubuntu:/usr/local/nginx$./sbin/nginx-t
Nginx: [alert] could not open error log file:open () "/usr/local/nginx/logs/error.log" failed (13:permission denied)
Nginx:the configuration file/usr/local/nginx/conf/nginx.conf syntax is OK
2012/01/09 16:45:09 [Emerg] 23898#0:open () "/usr/local/nginx/logs/nginx.pid" failed (13:permission denied)
Nginx:configuration file/usr/local/nginx/conf/nginx.conf Test Failed

If you receive a prompt like this, which means that you do not have access to the error log files and processes, you can sudo (super user do):
Copy Code code as follows:

poerchant@ubuntu:/usr/local/nginx$ sudo./sbin/nginx-t
Nginx:the configuration file/usr/local/nginx/conf/nginx.conf syntax is OK
Nginx:configuration file/usr/local/nginx/conf/nginx.conf Test is successful

If displayed as above, the configuration file is correct. Otherwise, there will be a hint.

7. Display Help information

Copy Code code as follows:
poechant@ubuntu:/user/local/nginx$./sbin/nginx-h

Or:

Copy Code code as follows:
poechant@ubuntu:/user/local/nginx$./sbin/nginx-?

These cover all the basic operations of Nginx's day-to-day maintenance, plus commands to send signals to the master process, which we'll see below.

Ii. commands for sending signals through master under Linux

Stop operation
The stop operation is done by sending a signal to the nginx process (what is a signal refer to a Linux article)
Step 1: Query Nginx main process number
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:
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:
Kill-Signal type '/usr/nginx/logs/nginx.pid ' (recommended)

Smooth reboot
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:
Kill-hup live in the title or process number file path
or use

Copy Code code as follows:
Nginx-s Reload (recommended)
Or
/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:
Nginx-t-c/usr/nginx/conf/nginx.conf
Or
NGINX-T (recommended)
Or
/usr/nginx/sbin/nginx-t

Smooth upgrade
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, replace the old program files with a new program, and compile the installation, the new program is compiled 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.

At this point, we can decide to use the new version or revert to the old version.
To start a new/old worker process without overloading the configuration
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.

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.