Linux Nginx Boot restart

Source: Internet
Author: User
Tags file permissions

1. First, create the Nginx file under the/etc/init.d/directory of the Linux system

Vim/etc/init.d/nginx

2. Adding a script

1 #!/bin/bash2 #nginx Startup script for the Nginx HTTP Server3 #it is v.0.0.2 version.4 #chkconfig:- about5 #Description:nginx is a high-performance Web and proxy server.6 #It has a lot of features, but it's not for everyone.7 #Processname:nginx8 #pidfile:/var/run/nginx.pid9 #Config:/usr/local/nginx/conf/nginx.confTennginxd=/usr/local/nginx/sbin/Nginx OneNginx_config=/usr/local/nginx/conf/nginx.conf Anginx_pid=/var/run/nginx.PID -Retval=0 -Prog= "Nginx" the #Source function Library. -. /etc/rc.d/init.d/functions - #Source networking configuration. -. /etc/sysconfig/Network + #Check that networking are up. -[${networking} = "No"] &&Exit0 +[-X$nginxd] ||Exit0 A #Start nginx daemons functions. at start () { - if[-E$nginx _pid];then -    Echo"Nginx already running ..." -    Exit1 - fi -    Echo-N $ "starting$prog: " inDaemon$nginxd-C ${nginx_config} -Retval=$? to    Echo +[$RETVAL= 0] &&Touch/var/lock/subsys/Nginx -    return $RETVAL the } * #Stop nginx daemons functions. $ Stop () {Panax Notoginseng         Echo-N $ "stopping$prog: " -Killproc$nginxd theRetval=$? +         Echo A[$RETVAL= 0] && rm-f/var/lock/subsys/nginx/var/run/nginx.PID the } + #Reload Nginx service functions. - Reload () { $     Echo-N $ "reloading$prog: " $     #kill-hup ' cat ${nginx_pid} ' -Killproc$nginxd-HUP -Retval=$? the     Echo - }Wuyi #See how we were called. the  Case"$"inch - start) Wu Start -         ;; About stop) $ Stop -         ;; - Reload) - Reload A         ;; + restart) the Stop - Start $         ;; the status) theStatus$prog theRetval=$? the         ;; -*) in         Echo$ "Usage:$prog{Start|stop|restart|reload|status|help} " the         Exit1 the Esac About Exit $RETVAL
View Code

or script:

1 #!/bin/bash2 #nginx Startup script for the Nginx HTTP Server3 #it is v.0.0.2 version.4 #chkconfig:- about5 #Description:nginx is a high-performance Web and proxy server.6 #It has a lot of features, but it's not for everyone.7 #Processname:nginx8 #pidfile:/var/run/nginx.pid9 #Config:/usr/local/nginx/conf/nginx.confTennginxd=/usr/local/nginx/sbin/Nginx OneNginx_config=/usr/local/nginx/conf/nginx.conf Anginx_pid=/var/run/nginx.PID -Retval=0 -Prog= "Nginx" the #Source function Library. -. /etc/rc.d/init.d/functions - #Source networking configuration. -. /etc/sysconfig/Network + #Check that networking are up. -[${networking} = "No"] &&Exit0 +[-X$nginxd] ||Exit0 A #Start nginx daemons functions. at start () { - if[-E$nginx _pid];then -    Echo"Nginx already running ..." -    Exit1 - fi -    Echo-N $ "starting$prog: " inDaemon$nginxd-C ${nginx_config} -Retval=$? to    Echo +[$RETVAL= 0] &&Touch/var/lock/subsys/Nginx -    return $RETVAL the } * #Stop nginx daemons functions. $ Stop () {Panax Notoginseng         Echo-N $ "stopping$prog: " -Killproc$nginxd theRetval=$? +         Echo A[$RETVAL= 0] && rm-f/var/lock/subsys/nginx/var/run/nginx.PID the } + #Reload Nginx service functions. - Reload () { $     Echo-N $ "reloading$prog: " $     #kill-hup ' cat ${nginx_pid} ' -Killproc$nginxd-HUP -Retval=$? the     Echo - }Wuyi #See how we were called. the  Case"$"inch - start) Wu Start -         ;; About stop) $ Stop -         ;; - Reload) - Reload A         ;; + restart) the Stop - Start $         ;; the status) theStatus$prog theRetval=$? the         ;; -*) in         Echo$ "Usage:$prog{Start|stop|restart|reload|status|help} " the         Exit1 theEsac
View Code

SOURCE from: https://www.nginx.com/resources/wiki/start/topics/examples/redhatnginxinit/

Notice where

nginx= "/usr/sbin/nginx" to modify the path of the Nginx execution program.

Nginx_conf_file= "/etc/nginx/nginx.conf" is modified to the path of the configuration file.

3. Set file permissions

chmod A+x/etc/init.d/nginx

4. Using Chkconfig for Management

Add Nginx service to Chkconfig management list first:

Chkconfig--add/etc/init.d/nginx

After adding this, you can use the service to start, restart, and so on Nginx operation.

Service Nginx StartService Nginx stop

5. Set up terminal mode boot:

Chkconfig Nginx on

Other references:

52463026

Https://www.cnblogs.com/jimisun/p/8057156.html

Linux Nginx Boot restart

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.