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.