[Nginx] startup, stop, and reload under Linux

Source: Internet
Author: User
Tags compact nginx server

Nginx Start-up 
/usr/local/nginx/sbin/nginx-c/usr/local/nginx/conf/nginx.conf  
Where the-c parameter specifies the configuration file path. Nginx's Stop Nginx supports the following kinds of signal control:-term, INT quick close-QUIT calmly close-HUP smooth restart-USR1 reopen log file, useful when cutting files-USR2 smooth upgrade-WINCH gracefully shut down the worker process we can stop the signal. To stop the Nginx main process, first, we need to get the master process PID via the Ps-ef|grep command, or get the main process number through the cat PID file. Here are a few typical stop statements:
#从容停止Nginx   -QUIT Master process number  #快速停止Nginx  -termmaster process number  #强制停止Nginx  -9 Master Process number  

Nginx Reload If you change the configuration file, you want to restart it to take effect, you can also send the system signal to the Nginx master process, but before restarting, to confirm that the configuration file syntax is correct, otherwise the new configuration item will not be loaded. Test the configuration file syntax correctly with the following statement:
/usr/local/nginx/sbin/nginx-t-c/usr/local/nginx/conf/nginx.conf  

Where-T indicates a test and is not actually executed. Then, reload the Nginx configuration with the following command:
After executing the above command, Nginx runs the new worker process, and the old worker process continues to be the existing connection service, and after all the old connections are successful, the old worker process is closed.

Nginx Startup script
#!/bin/sh # chkconfig:2345  -  the# Description:nginx Server nginx_home=/usr/local/Nginx Nginx_sbin= $NGINX _home/sbin/Nginx nginx_conf= $NGINX _home/conf/nginx.conf nginx_pid= $NGINX _home/logs/nginx.pid Nginx_name="Nginx"    . /etc/rc.d/init.d/functionsif[ ! -F $NGINX _sbin] then echo"$NGINX _name Startup: $NGINX _sbin not exists!"exit fi Start () {$NGINX _sbin-c $NGINX _conf ret=$?if[$ret-eq0 ]; Then action $"starting $NGINX _name:"/bin/true      ElseAction $"starting $NGINX _name:"/bin/falsefi} Stop () {kill ' cat $NGINX _pid ' ret=$?if[$ret-eq0 ]; Then action $"stopping $NGINX _name:"/bin/true      ElseAction $"stopping $NGINX _name:"/bin/falsefi} restart () {Stop start} check () {$NGINX _sbin-C $NGINX _conf-T} reload () {Kill-hup ' cat $NGINX _pid ' && Echo"Reload success!"} relog () {Kill-USR1 ' cat $NGINX _pid ' && Echo"relog success!"  }     Case " $" inchstart) Start;      stop) stop;;      restart) restart;; Check|chk) check;; Status) Status-p $NGINX _pid;;      reload) reload;;      relog) relog;; *) echo $"Usage: $ {Start|stop|restart|reload|status|check|relog}"Exit1Esac
The above is the Nginx startup script, as long as it is copied to the/ETC/INIT.D directory, you can use the service nginx start directory operation Nginx.

In addition to the methods described above that directly signal the Nginx master process, we can also use the Nginx-s command:
    • stop-fast shutdown
    • quit-graceful shutdown
    • reload-reloading the configuration file
    • reopen-reopening the log files

[Nginx] startup, stop, and reload under Linux

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.