To set the Nginx boot auto Start method

Source: Internet
Author: User

Linux Nginx Server Automatic startup method steps:

First, create the Nginx file in the/etc/init.d/directory of the Linux system, using the following command:

Vim/etc/init.d/nginx

Add the following command to the script: (Note that the red is the Nginx installation directory, now the red part is my installation directory, do not replace your Nginx installation directory This thing is not work)

#!/bin/bash # nginx Startup script for the Nginx HTTP Server # It is v.0.0.2 version.
# Chkconfig:-Description:nginx is a high-performance Web and proxy server.
#              It has a lot of features, but it ' s not for everyone. # Processname:nginx # pidfile:/var/run/nginx.pid # config:/usr/local/nginx/conf/nginx.conf nginxd=/usr/local/nginx/ Sbin/nginx nginx_config=/usr/local/nginx/conf/nginx.conf nginx_pid=/var/run/nginx.pid RETVAL=0 prog= "Nginx" # Source
function library. .
/etc/rc.d/init.d/functions # Source Networking configuration. .
/etc/sysconfig/network # Check that networking are up. [${networking} = "No"] && exit 0 [-x $nginxd] | |
Exit 0 # Start Nginx daemons functions.  Start () {if [e $nginx _pid];then    echo Nginx already running ... "   exit 1 fi    echo
-N $ "starting $prog:"    daemon $nginxd-C ${nginx_config}    retval=$?    echo    [$REtval = 0] && touch/var/lock/subsys/nginx    return $RETVAL} # Stop Nginx daemons functions. Stop () {        ECHO-N $ "stopping $prog:"         Killproc $nginxd   &NBSP ;
    retval=$?         echo         [$RETVAL = 0] && rm-f/var/lock/subsys/nginx/var/
Run/nginx.pid} # Reload Nginx service functions. Reload () {    echo-n $ "reloading $prog:"     #kill-hup ' cat ${nginx_pid} '     Killproc $
Nginxd-hup     retval=$?
    Echo} # How we were called.
Case "$" in start)         start        
Stop)         stop        ;;
Reload)         Reload        ;;
Restart)         stop         start      ; Status)     &NBSp
  Status $prog         retval=$?
       ;; *         echo $ "Usage: $prog {start|stop|restart|reload|status|help}"         EX
 It 1 Esac exit $RETVAL

Use Chkconfig for management (this is normally the default is OK, plus to avoid the input command does not work)

First add the Nginx service to the Chkconfig management list:

Chkconfig--add/etc/init.d/nginx

After adding this, you can use the service to start the Nginx, restart, and so on.

Service Nginx start
service Nginx stop

Last step: Set terminal mode to boot:

Chkconfig Nginx on
And then it was strong.

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.