Nginx is a powerful high-performance Web and reverse proxy server. Here's how to set up boot after installing under Linux.
First, create the Nginx file under the/etc/init.d/directory of the Linux system, using the following command:
Vi/etc/init.d/nginx
Add the following command to the script:
*************************************************************************************************************** ******************
#!/bin/bash# nginx Startup script forThe Nginx HTTP server# It is v.0.0.2version.# chkconfig:- - the# 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.confnginxd=/usr/local/nginx/sbin/nginxnginx_config=/ usr/local/nginx/conf/nginx.confnginx_pid=/var/run/ nginx.pidRETVAL=0Prog="Nginx"# SourcefunctionLibrary:/etc/rc.d/init.d/functions# Source Networking configuration:/etc/sysconfig/network# Check that networking are up. [${networking}="No"] && exit0[ -X $nginxd] | | Exit0# Start Nginx daemons Functions.start () {if[-e $nginx _pid]; Then Echo "Nginx already running ...."Exit1fi 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 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}# See how we were called. Case " $" inchstart) Start; stop) stop;; reload) reload;; restart) stop start;; Status) status $prog RETVAL=$? ;;*) Echo$"Usage: $prog {start|stop|restart|reload|status|help}"Exit1EsacExit $RETVAL
*************************************************************************************************************** ******************
Note the Red Bold section, you need to change the path to the corresponding path of your machine.
Next, set access permissions for the file:
chmod a+x/etc/init.d/nginx (a+x parameter means ==> all user can execute All users can execute)
Finally, add the Ngix to the rc.local file so that the Nginx will start by default.
Vi/etc/rc.local
Add to
/etc/init.d/nginx start
Save and exit
The next reboot will take effect, realizing nginx self-booting.
Installation of Nginx boot from Linux (CentOS) system