Nginx 啟動(dòng)腳本/重啟腳本代碼_Web服務(wù)器教程
Nginx 啟動(dòng)腳本 重啟腳本,學(xué)習(xí)使用centos配置服務(wù)器的朋友可以參考下。
第一步
先運(yùn)行命令關(guān)閉nginx
sudo kill `cat /usr/local/nginx/logs/nginx.pid`
第二步
vi /etc/init.d/nginx
輸入以下內(nèi)容
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemin
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /usr/local/nginx/conf/nginx.conf
# pidfile: /usr/local/nginx/logs/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
lockfile=/var/lock/subsys/nginx
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
start
}
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 "$1" in
start)
rh_status_q && exit 0
$1
stop)
rh_status_q || exit 0
$1
restart|configtest)
$1
reload)
rh_status_q || exit 7
$1
force-reload)
force_reload
status)
rh_status
condrestart|try-restart)
rh_status_q || exit 0
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
保存退出
第三步
chmod +x /etc/init.d/nginx
第四步
/sbin/chkconfig nginx on
檢查一下
sudo /sbin/chkconfig --list nginx
nginx 0:off 1:off 2:on 3:on 4:on 5:on 6:off
完成!
之后,就可以使用以下命令了
service nginx start
service nginx stop
service nginx restart
service nginx reload
/etc/init.d/nginx start
/etc/init.d/nginx stop
/etc/init.d/nginx restart
/etc/init.d/nginx reload
下面是其它作者發(fā)布的文章
#vi /etc/init.d/nginx
#! /bin/sh
### BEGIN INIT INFO
# Provides: Nginx-php-fpm(fastcgi)
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 3 5
# Default-Stop: 0 1 6
# Short-Description: Start and stop nginx-fcgi in external FASTCGI mode
# Description: Start and stop nginx-fcgi in external FASTCGI mode
# http://www.linxutone.org msn:cnseek@msn.com
### END INIT INFO
set -e
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="nginx daemon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
CONFIGFILE=/usr/local/nginx/conf/nginx.conf
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0
d_start() {
/usr/local/php-fcgi/sbin/php-fpm start > /dev/null 2>&1
$DAEMON -c $CONFIGFILE || echo -n " already running"
}
d_stop() {
/usr/local/php-fcgi/sbin/php-fpm stop > /dev/null 2>&1
kill -QUIT `cat $PIDFILE` || echo -n " not running"
}
d_reload() {
/usr/local/php-fcgi/sbin/php-fpm reload > /dev/null 2>&1
kill -HUP `cat $PIDFILE` || echo -n " can't reload"
}
case "$1" in
start)
echo -n "Starting $DESC: $NAME"
d_start
echo "."
stop)
echo -n "Stopping $DESC: $NAME"
d_stop
echo "."
reload)
echo -n "Reloading $DESC configuration ..."
d_reload
echo "reloaded."
restart)
echo -n "Restarting $DESC: $NAME"
d_stop
sleep 1
d_start
echo "."
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2
exit 3
esac
exit 0
#chmod u+x /etc/init.d/nginx
使用方法:
#/etc/init.d/nginx start
#/etc/init.d/nginx stop
#/etc/init.d/nginx restart
注意修改安裝路徑了
復(fù)制代碼 代碼如下:
#!/bin/bash
#
# Init file for nginx server daemon
#
# chkconfig: 234 99 99
# description: nginx server daemon
#
# source function library
. /etc/rc.d/init.d/functions
# pull in sysconfig settings
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
RETVAL=0
prog="nginx"
PAT=/usr/local/nginx
NGINXD=/usr/local/nginx/sbin/nginx
PID_FILE=/usr/local/nginx/nginx.pid
start()
{
echo -n $"Starting $prog: "
$NGINXD 2>/dev/null $OPTIONS && success || failure
RETVAL=$?
[ "$RETVAL" = 0 ] && touch /var/lock/subsys/nginx
echo
}
stop()
{
echo -n $"Shutting down $prog: "
killproc nginx
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/nginx
return $RETVAL
}
reload()
{
echo -n $"Reloading nginx: "
killproc nginx -HUP
RETVAL=$?
echo
return $RETVAL
}
case "$1" in
start)
start
stop)
stop
restart)
stop
start
reload)
reload
status)
status -p $PID_FILE nginx
RETVAL=$?
*)
echo $"Usage: $0 {start|stop|restart|reload|status}"
RETVAL=1
esac
exit $RETVAL
相關(guān)Web服務(wù)器教程:
- 推薦!各類(lèi)建站程序偽靜態(tài)規(guī)則代碼
- 詳細(xì)的DedeCMS(織夢(mèng))目錄權(quán)限安全設(shè)置教程
- iis安全設(shè)置全方位教程
- 巧妙出招致勝服務(wù)器管理
- Win Server 2003個(gè)人網(wǎng)絡(luò)服務(wù)器安全攻略
- Windows 2003校園Web服務(wù)器常見(jiàn)問(wèn)題
- 清除IIS配置文件后門(mén)隱患
- Web服務(wù)器和應(yīng)用程序服務(wù)器有什么區(qū)別
- 虛擬主機(jī)下asp.net 2.0的導(dǎo)航控件treeview,menu等出錯(cuò)
- IIS6.0服務(wù)器架站無(wú)法訪問(wèn)解決方案總結(jié)
- 圖解支持多語(yǔ)言環(huán)境的IIS服務(wù)器配置
- IIS服務(wù)器排錯(cuò)指南及錯(cuò)誤代碼大全
Web服務(wù)器教程Rss訂閱服務(wù)器教程搜索
Web服務(wù)器教程推薦
- WEB專用服務(wù)器的安全設(shè)置的實(shí)戰(zhàn)技巧
- IIS開(kāi)啟GZIP壓縮效率對(duì)比及部署方法
- 利用IIS建立高安全性Web服務(wù)器
- 在Windows系統(tǒng)上安裝PHP應(yīng)用程序服務(wù)器
- 詳解FreeBSD8下安裝Apache+MySQL+PHP5
- 防止黑客入侵WEB服務(wù)器三步曲!
- 當(dāng)今幾大主流服務(wù)器的操作系統(tǒng)特性概述
- 如何讓IIS上支持WAP網(wǎng)站?
- 關(guān)于IIS連接數(shù)和在線人數(shù)的詳細(xì)說(shuō)明
- 偽靜態(tài)在iis下的規(guī)則和設(shè)置方法
猜你也喜歡看這些
- Win2003 防木馬、權(quán)限設(shè)置、IIS服務(wù)器安全配置整理
- IIS中RPC服務(wù)器不可用的解決方法
- 微博縮短網(wǎng)址是如何實(shí)現(xiàn)的
- FTP服務(wù)器(Serv-U)快速架設(shè)步驟
- ISAPI Rewrite實(shí)現(xiàn)IIS 301轉(zhuǎn)向
- 介紹服務(wù)器安全熱點(diǎn)12項(xiàng)技術(shù)
- 網(wǎng)站性能優(yōu)化之Apache調(diào)整
- 服務(wù)器虛擬化技術(shù):虛擬機(jī)優(yōu)化小竅門(mén)
- 網(wǎng)絡(luò)安全教程:遠(yuǎn)程訪問(wèn)入侵的抵御
- nginx緩存cache的5種方案
- 相關(guān)鏈接:
- 教程說(shuō)明:
Web服務(wù)器教程-Nginx 啟動(dòng)腳本/重啟腳本代碼。