[Nginx] start, stop, and reload in Linux

Source: Internet
Author: User
Start usrlocalnginxsbinnginx-cusrlocalnginxconfnginxconf of Nginx. the-c parameter specifies the configuration file path. Nginx stop Nginx supports the following signal control:-TERM, INT quick close-QUIT easy close-HUP Nginx start
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
The-c parameter specifies the path of the configuration file.
Nginx stop Nginx supports the following signal control:-TERM, INT quick close-QUIT easy close-HUP smooth restart-USR1 re-open the log file, when cutting files, use big-USR2 smooth upgrade-WINCH calmly shut down the working process. we can stop the main Nginx process by signal. first, run the ps-ef | grep command to obtain the PID of the master process, or use the cat pid file to obtain the master process number. Below are several typical stop statements:
# Stop Nginxkill-QUIT master process no. # Stop Nginxkill-TERM master process no. # force stop Nginxkill-9 master process no.

If the configuration file is changed during Nginx reload and you want to restart it to make it take effect, you can also send a system signal to the Nginx main process. However, before restarting, make sure that the syntax of the configuration file is correct. Otherwise, the new configuration item will not be loaded. Use the following statement to test whether the configuration file syntax is correct:
/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
-T indicates that the test is not actually executed. Then, run the following command to reload the Nginx configuration:
Kill-HUP master process number
After executing the preceding command, Nginx runs a new working process, and the old working process continues to serve as an existing connection. after all the old connections are successful, the old working process is closed.

Nginx startup script
#!/bin/sh# chkconfig: 2345 85 15# description:Nginx ServerNGINX_HOME=/usr/local/nginxNGINX_SBIN=$NGINX_HOME/sbin/nginxNGINX_CONF=$NGINX_HOME/conf/nginx.confNGINX_PID=$NGINX_HOME/logs/nginx.pidNGINX_NAME="Nginx". /etc/rc.d/init.d/functionsif [ ! -f $NGINX_SBIN ]then    echo "$NGINX_NAME startup: $NGINX_SBIN not exists! "    exitfistart() {    $NGINX_SBIN -c $NGINX_CONF    ret=$?    if [ $ret -eq 0 ]; then        action $"Starting $NGINX_NAME: " /bin/true    else        action $"Starting $NGINX_NAME: " /bin/false    fi}stop() {    kill `cat $NGINX_PID`    ret=$?    if [ $ret -eq 0 ]; then        action $"Stopping $NGINX_NAME: " /bin/true    else        action $"Stopping $NGINX_NAME: " /bin/false    fi}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 "$1" in    start)        start        ;;    stop)        stop        ;;    restart)        restart        ;;    check|chk)        check        ;;    status)        status -p $NGINX_PID        ;;    reload)        reload        ;;    relog)        relog        ;;    *)        echo $"Usage: $0 {start|stop|restart|reload|status|check|relog}"        exit 1esac
The above is the nginx startup script. as long as you copy it to the/etc/init. d directory, you can operate nginx through the directory such as service nginx start.

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.