Help: -? -h Uses the specified configuration file: -c Specifies the configuration command: -g specifies the running directory: -p Sends signals:-s[Stop the service now: stop Gracefully: quit Reload the configuration file: reload the log file: reopen] The configuration file is tested to see if there is an error: -t -t Displays the nginx version information, and the compilation information is -v -vCopy the code


How to gracefully update nginx configuration?

When you have a very large number of users, your background service can not just stop and stop, and then stop service every time to do updates, or some operations;

For example, you need to upgrade the latest version of Nginx

Compile an objs file as described in the initial compilation of Nginx, and then use the following operations to back up, replace, and restart Nginx

1. Go to the path specified after compilation –prefix and find the binary directory

$cp nginx nginx.oldCopy the code

2. Copy the objs/nginx binary file of the newly compiled file to /home/nginx/sbin

$cp -r nginx /home/nginx/sbin -f Copy the code

3. Run the ps command to view the current Nginx process number

$ps -ef|grep nginx
$kill- USR2 PIDCopy the code

A new master process has been started, which is equivalent to the synchronization of the old and new processes, but the old process is no longer listening to the port. After this, you need to send the following command to shut down the old worker process.

$kill- the WINCH old PIDCopy the code

The new version of nginx disables the old worker process, but does not disable the old master process.

The reason is that you can’t guarantee that your new version of Nginx will work, and this process can also accept the reload command to roll back to the old version





Two, log cutting, scheduled task

$crontab -lCopy the code

The scheduled task script is as follows

#! /bin/bash
LOGS_PATH = /home/nginx/logs/history
CURRENT_LOGS_PATH = /home/nginx/logs
YESTERDAY = $(date -d "yesterday" +%Y-%m-%d)
mv ${CURRENT_LOGS_PATH}/access.log ${LOGS_PATH}/access_${YESTERDAY}.log
mv ${CURRENT_LOGS_PATH}/error.log ${LOGS_PATH}/error_${YESTERDAY}.log
kill -USR1 $(cat /home/nginx/logs/nginx.pid)Copy the code