CentOS system sets Nginx service to start and run automatically
After completing the basic configuration of nginx, you can configure it as a service for easy management. At the same time, the service can be automatically started when the system starts. 1. First configure the service script and create the file /etc/rc.d/init.d/nginx2, the content of which is as follows: #!/bin/sh #chkconfig: 2345 10 90 #name: nginx #description: Nginx Service Script # case $1 in start) Echo “Starting Nginx…” /usr/local/nginx2/sbin/nginx -c /usr/local/nginx2/conf/nginx.conf ;; stop) echo “Stopping Nginx…” /usr/bin/killall -s QUIT nginx ;; restart) echo “Reloading Nginx…” $0 stop $0 start ;; *) Echo “Usage: $0 {start|stop|restart}” esac exit 0 2. Configure autostart chkconfig –add nginx2 //Add to self-starting service chkconfig –level 2345 nginx2 off //Adjust the start of different system levels chkconfig –level 2345 nginx2 on //Adjust the start of different system levels chkconfig | grep nginx2 //View status