#! /Bin/sh # nginx-this script starts and stops the nginx daemon # chkconfig:-85 15 # Description: nginx is an HTTP (s) server, HTTP (s) reverse \ # proxy and IMAP/POP3 Proxy Server # processname: nginx # config:/etc/nginx. conf # config:/etc/sysconfig/nginx # pidfile:/var/run/nginx. pid # source function library .. /etc/rc. d/init. d/functions # source networking configuration .. /etc/Sysco Nfig/Network # Check that networking is up. ["$ networking" = "no"] & Exit 0 ##### path of the nginx execution program ###### nginx = "/usr/local/nginx/ sbin/nginx "prog =$ (basename $ nginx) ##### path of the nginx configuration file ##### nginx_conf_file = "/etc/nginx. conf "[-F/etc/sysconfig/nginx] &. /etc/sysconfig/nginx lockfile =/var/lock/subsys/nginx make_dirs () {# Make Required Directories user = 'nginx-V 2> & 1 | grep "Configure argu Ments: "| SED's/[^ *] * -- user = \ ([^] * \). */\ 1/G'-'Options = '$ nginx-V 2> & 1 | grep 'configure arguments: ''for opt in $ options; do if ['echo $ opt | grep '. *-temp-path '']; then value = 'echo $ opt | cut-d" = "-F 2' if [! -D "$ value"]; then # echo "Creating" $ value mkdir-p $ Value & chown-r $ user $ value fi done} start () {[-x $ nginx] | Exit 5 [-F $ nginx_conf_file] | exit 6 make_dirs echo-N $ "Starting $ prog: "daemon $ nginx-C $ nginx_conf_file retval =$? Echo [$ retval-EQ 0] & touch $ lockfile return $ retval} STOP () {echo-N $ "Stopping $ prog:" killproc $ prog-Quit retval =$? Echo [$ retval-EQ 0] & Rm-F $ lockfile return $ retval} restart () {configtest | return $? Stop sleep 1 start} 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 "$1" in START) rh_status_q & Exit 0 $1; stop) rh_status_q | exit 0 $1 ;; restart | configtest) $1; RELOAD) rh_status_q | exit 7 $1; force-Reload) force_reload; Status) rh_status; condrestart | try-Restart) rh_status_q | exit 0; *) echo $ "Usage: $0 {START | stop | status | restart | condrestart | try-Restart | reload | force-Reload | configtest} "Exit 2 esac
Save the preceding content as/etc/init. d/nginx and add executable permissions,
Add another system service, chkconfig -- add nginx
The last step is to start the system: chkconfig nginx on
Start: Service nginx start
View status: netstat-ntlp | grep 80
This article from the "sense of direction" blog, please be sure to keep this source http://itech.blog.51cto.com/192113/1616874
System Service nginx startup control script