Linux boot automatically start nginx service

Source: Internet
Author: User

1. If I have an Nginx installation guide on my blog, first my Nginx path is:/application/nginx/sbin/Nginx;2The path to my nginx configuration file is:/application/nginx/conf/nginx.conf. The following is the Nginx service boot file, will be placed in/etc/init.d/directory, the file name is: Nginx. #!/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="/application/nginx/sbin/nginx"Prog=$ (basename $nginx) Nginx_conf_file="/application/nginx/conf/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

Finally, don't forget: chkconfig Nginx on can be following familiar command management: Service Nginx statusservice nginx startservice nginx stopservice nginx Restart

Linux boot automatically start nginx service

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.