首頁 > php教程 > PHP开发 > 主體

nginx開機自動啟動服務

高洛峰
發布: 2016-12-01 13:33:12
原創
1375 人瀏覽過

生產伺服器:

OS:CentOS 6.8

1.在該目錄下」/etc/init.d」新建一個nginx文件,新增下列程式碼。

[root@localhost init.d]# vi  nginx

[root@localhost init.d]# vi  nginx

[root@localhost init.d]# vi  nginx

[root@localhost init.d]# vi  nginx

[root@localhost init.d]# cat nginx

#nginx Startup script for the Nginx HTTP Server

#nginx Startup script for the Nginx HTTP Server

.

# chkconfig: - 85 15

# description: Nginx is a high-performance web and proxy server.

# It has a lot of features, but it's not for # It has a lot of features, but it's not for . /var/run/nginx.pid

# config: /usr/local/nginx/conf/nginx.conf

nginxd=/application/nginx/sbin/ngcationx

nginx_config= conf

nginx_pid=/var/run/nginx.pid

RETVAL=0

prog="nginx"

# Source function library.

./etc/rc.d/unction Source networking configuration.

./etc/sysconfig/network

# Check that networking is up.

[ ${NETWORKING} = "no" ] && exit 0

[ ${NETWORKING} = "no" ] && exit 0

[ ${NETWORKING} = "no" ] && exit 0

[ ${NETWORKING} = "no" ] && exit 0

🜎

# Start nginx daemons functions.

start() {

if [ -e $nginx_pid ];then

   $" Starting $prog: "

   daemon $nginxd -c ${nginx_config}

   RETVAL=$?

   echo

VAL

}

# Stop nginx daemons functions.

stop() {

        echo -n $"Stop   RETVAL=$?

        echo

        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid

}

# reload nginx service functions.

reload() { #kill -HUP `cat ${nginx_pid}`

    killproc $nginxd -HUP

    RETVAL=$?

  . echoase

. in

start)

        start

        ;;

stop)

        stop

        ;;

reload)

        reload

        ;;

restart)

        stop

        start

        ;;

status)

        status $prog

        RETVAL=$?

        ;;

*)

  

        exit 1

esac

exit $ RETVAL

2.設定開機啟動服務,儲存好 /etc/init.d/nginx檔案後,執行下列指令:

[root@localhost init.d]# chmod 755 /etc/init.d/nginx #文件執行權限

[root@localhost init.d]# chkconfig --add nginx

[root@localhost init.d]# chkconfig --add nginx

[root@localhost init.d]# chkconfig  --level 2345  nginx  on 1無間斷服務重啟

[root@localhost /]# service nginx status

nginx (pid 1621 1619) 正在運作...

[                                  地

[root@localhost /]# service nginx start

正在啟動nginx:                  

[root@localhost /]# service nginx reload

重接                  [確定]

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門推薦
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板