1. Create a script file nginxd
[Root @ nginx canyoungx] # vi/etc/init. d/nginxd
Insert the following content
#! /Bin/bash
#
# Chkconfig:-85 15
# Description: nginx is a World Wide Web server.
# Processname: nginx
Nginx =/usr/local/nginx/sbin/nginx
Conf =/usr/local/nginx/CONF/nginx. conf
Case $1 in
Start)
Echo-n "Starting nginx"
$ Nginx-C $ Conf
Echo "done"
;;
Stop)
Echo-n "Stopping nginx"
Killall-9 nginx
Echo "done"
;;
Test)
$ Nginx-T-C $ Conf
;;
Reload)
Echo-n "reloading nginx"
PS auxww | grep nginx | grep master | awk '{print $2}' | xargs kill-HUP
Echo "done"
;;
Restart)
$0 stop
$0 start
;;
Show)
PS-Aux | grep nginx
;;
*)
Echo-n "Usage: $0 {START | restart | reload | stop | test | show }"
;;
Esac
2. Change the nginxd permission
[Root @ nginx canyoungx] # chmod 777/etc/init. d/nginxd
3. Set startup
[root @ nginx canyoungx] # chkconfig nginxd on