>백엔드 개발 >PHP 튜토리얼 >Nginx 시리즈(Three.nginx는 Linux 시스템 서비스로 등록되어 있습니다)

Nginx 시리즈(Three.nginx는 Linux 시스템 서비스로 등록되어 있습니다)

WBOY
WBOY원래의
2016-08-08 09:24:561302검색

一、创建服务脚本

<code>vim /etc/init<span>.d</span>/nginx</code>

脚本内容如下

<code><span>#! /bin/sh</span><span># chkconfig: - 85 15</span>PATH=/web/server/nginx/sbin

DESC=<span>"nginx daemon"</span>
NAME=nginx
DAEMON=/web/server/nginx/sbin/<span>$NAME</span>
CONFIGFILE=/web/server/nginx/conf/<span>$NAME</span>.conf
PIDFILE=/web/server/nginx/logs/<span>$NAME</span>.pid
SCRIPTNAME=/etc/init.d/<span>$NAME</span><span>set</span><span>-e</span>
[ -x <span>"<span>$DAEMON</span>"</span> ] || <span>exit</span><span>0</span><span><span>do_start</span></span>() {
<span>$DAEMON</span> -c <span>$CONFIGFILE</span> || <span>echo</span> -n <span>"nginx already running"</span>
}

<span><span>do_stop</span></span>() {
<span>$DAEMON</span><span>-s</span> stop || <span>echo</span> -n <span>"nginx not running"</span>
}

<span><span>do_reload</span></span>() {
<span>$DAEMON</span><span>-s</span> reload || <span>echo</span> -n <span>"nginx can't reload"</span>
}

<span>case</span><span>"<span>$1</span>"</span><span>in</span>
start)
<span>echo</span> -n <span>"Starting <span>$DESC</span>: <span>$NAME</span>"</span><span>do</span>_start
<span>echo</span><span>"."</span>
;;
stop)
<span>echo</span> -n <span>"Stopping <span>$DESC</span>: <span>$NAME</span>"</span><span>do</span>_stop
<span>echo</span><span>"."</span>
;;
reload|graceful)
<span>echo</span> -n <span>"Reloading <span>$DESC</span> configuration..."</span><span>do</span>_reload
<span>echo</span><span>"."</span>
;;
restart)
<span>echo</span> -n <span>"Restarting <span>$DESC</span>: <span>$NAME</span>"</span><span>do</span>_stop
<span>do</span>_start
<span>echo</span><span>"."</span>
;;
*)
<span>echo</span><span>"Usage: <span>$SCRIPTNAME</span> {start|stop|reload|restart}"</span> >&<span>2</span><span>exit</span><span>3</span>
;;
<span>esac</span><span>exit</span><span>0</span></code>

二、添加服务

<code><span>chkconfig</span><span>-</span><span>-</span><span>add</span><span>nginx</span></code>

三、测试

<code>service nginx <span><span>start</span></span></code>
<code>service nginx <span>stop</span></code>
<code>service nginx restart</code>
<code>service nginx reload</code>

以上就介绍了Nginx系列(三.nginx注册为linux系统服务),包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.