After adding Nginx service, you will want to start with the boot nginx, to avoid manual path input start;
Nginx officially provides a startup script: https://www.nginx.com/resources/wiki/start/topics/examples/redhatnginxinit/
I use the CentOS system here, first of all, into the/etc/init.d/directory, the newly added Nginx file, the contents of the above connection pasted into the Nginx file,
#!/bin/sh## Nginx- Thisscript starts and stops the Nginx daemon## chkconfig:- - the# Description:nginx isAn http (s) server, HTTP (s) reverse # Proxy and IMAP/POP3 proxy server# processname:nginx# config:/etc/nginx/nginx.conf# config:/etc/sysconfig/nginx# pidfile:/var/run/nginx.pid# Source function library:/etc/rc.d/init.d/functions# Source Networking configuration:/etc/sysconfig/network# Check that networking isUp . [ "$NETWORKING"="No"] && exit0Nginx="/usr/sbin/nginx"Prog=$ (basename $nginx) Nginx_conf_file="/etc/nginx/nginx.conf"[ -f/etc/sysconfig/nginx] &&. /etc/sysconfig/Nginxlockfile=/var/Lock/subsys/Nginxmake_dirs () {# Make required directories user= ' $nginx-V2>&1| Grep"Configure arguments:"| Sed's/[^*]*--user=\ ([^]*\). */\1/g'-` if[-Z"' grep $user/etc/passwd '" ]; Then Useradd-m-s/bin/nologin $user fi options= ' $nginx-V2>&1| Grep'Configure arguments:'` forOptinch$options; Do if[' Echo $opt | grep'. *-temp-path'` ]; Then value= ' echo $opt | Cut-d"="-F2` if[!-D"$value" ]; Then # echo"Creating"$value mkdir-P $value && chown-R $user $value fi fi done}start () {[-X $nginx] | | Exit5 [ -F $NGINX _conf_file] | | Exit6Make_dirs Echo-N $"starting $prog:"Daemon $nginx-c $NGINX _conf_file retval=$?Echo [$retval-eq0] &&Touch $lockfilereturn$retval}stop () {echo-N $"stopping $prog:"Killproc $prog-QUIT retval=$?Echo [$retval-eq0] && RM-F $lockfilereturn$retval}restart () {configtest||return$?Stop Sleep1start}reload () {configtest||return$?Echo-N $"Reloading $prog:"Killproc $nginx-HUP RETVAL=$?echo}force_reload () {restart}configtest () {$nginx-T-C $NGINX _conf_file}rh_status () {status $prog}rh_status_q () {rh_status>/dev/NULL 2>&1} Case " $" inchstart) Rh_status_q&& exit0 $1 ;; Stop) Rh_status_q|| Exit0 $1 ;; Restart|configtest) $1 ;; Reload) Rh_status_q|| Exit7 $1 ;; Force-reload) force_reload;; status) Rh_status;; Condrestart|Try-restart) rh_status_q|| Exit0 ;; *) echo $"Usage: $ {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"Exit2Esac
Two places need to be modified:
First: nginx="/usr/sbin/nginx" here to change to your Nginx installation when the boot file on the path, such as my nginx installed in the/usr/local/ Nginx, corresponding to the boot file in /usr/local/nginx/sbin/nginx, so the Nginx boot path to nginx="/usr/local/nginx/sbin/ Nginx"
Second: nginx_conf_file= "/etc/nginx/nginx.conf"
Here as above, my nginx configuration file is also placed in the/usr/local/nginx installation directory, specifically in/usr/local/nginx/conf/nginx.conf
So change the NGINX configuration path to nginx_conf_file= "/usr/local/nginx/conf/nginx.conf"
Save the Nginx file and then use Chkconfid to manage it, as follows
--add/etc/init.d/nginx
After adding the above, you can use the service to start, stop and restart the nginx operation.
#service nginx start#service nginx stop#service nginx Reload ...
If the service Nginx start with prompt useradd use error, then you can edit the Nginx file just created,
Navigate to the Start () method, make_dirs the inside of the line comment out, save exit, reboot once OK.
Nginx Set Boot start