Nginx 啟動腳本/重啟腳本代碼
更新時(shí)間:2010年10月03日 01:42:28 作者:
Nginx 啟動腳本 重啟腳本,學(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
注意修改安裝路徑了
#!/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
先運(yùn)行命令關(guān)閉nginx
sudo kill `cat /usr/local/nginx/logs/nginx.pid`
第二步
vi /etc/init.d/nginx
輸入以下內(nèi)容
復(fù)制代碼 代碼如下:
#!/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
完成!
之后,就可以使用以下命令了
復(fù)制代碼 代碼如下:
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ā)布的文章
復(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
使用方法:
復(fù)制代碼 代碼如下:
#/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
您可能感興趣的文章:
- nginx 多站點(diǎn)配置方法集合
- CentOS+Nginx+PHP+MySQL詳細(xì)配置(圖解)
- nginx 作為反向代理實(shí)現(xiàn)負(fù)載均衡的例子
- 一句簡單命令重啟nginx
- Nginx下301重定向域名的方法小結(jié)
- Nginx偽靜態(tài)配置和常用Rewrite偽靜態(tài)規(guī)則集錦
- nginx日志配置指令詳解
- Nginx 下配置SSL證書的方法
- NGINX下配置404錯(cuò)誤頁面的方法分享
- Nginx和PHP-FPM的啟動、重啟、停止腳本分享
- nginx rewrite 偽靜態(tài)配置參數(shù)和使用例子
- nginx 如何實(shí)現(xiàn)讀寫限流的方法
相關(guān)文章
阿里云Nginx配置https實(shí)現(xiàn)域名訪問項(xiàng)目(圖文教程)
這篇文章主要介紹了阿里云Nginx配置https實(shí)現(xiàn)域名訪問項(xiàng)目(圖文教程),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-09-09
nginx文件上傳限制以及超時(shí)無響應(yīng)問題的解決
小編最近開發(fā)前后端分離項(xiàng)目遇到一些問題,后端服務(wù)是基于80/443端口反向代理的,所以請求會經(jīng)過nginx網(wǎng)關(guān),然后將請求代理到后端服務(wù),這是開發(fā)環(huán)境,所以本文小編給大家介紹了解決nginx文件上傳限制和超時(shí)無響應(yīng),需要的朋友可以參考下2025-04-04
Nginx-rtmp實(shí)現(xiàn)直播媒體實(shí)時(shí)流效果
這篇文章主要介紹了Nginx-rtmp實(shí)現(xiàn)直播媒體實(shí)時(shí)流效果,文中給出了總體設(shè)計(jì)圖,為了整合平臺,會自建RTMP流媒體服務(wù)器和使用云廠商SaaS的RTMP流媒體服務(wù),需要的朋友可以參考下2018-08-08
nginx tcp負(fù)載均衡的具體實(shí)現(xiàn)
Nginx是比較不錯(cuò)的開源Web服務(wù)器之一,它也可以用作TCP和UDP負(fù)載均衡器,本文主要介紹了nginx tcp負(fù)載均衡的具體實(shí)現(xiàn),具有一定的參考價(jià)值,感興趣的可以了解一下2024-05-05
nginx配置同一域名同一端口下部署多個(gè)vue項(xiàng)目
本文主要介紹了nginx配置同一域名同一端口下部署多個(gè)vue項(xiàng)目,可以根據(jù)根路徑不同分別代理訪問不同項(xiàng)目,具有一定的參考價(jià)值,感興趣的可以了解一下2024-06-06
負(fù)載均衡下的webshell上傳+nginx解析漏洞的過程
這篇文章主要介紹了負(fù)載均衡下的webshell上傳+nginx解析漏洞,首先介紹了負(fù)載均衡下webshell上傳的四大難點(diǎn)及環(huán)境搭建教程,感興趣的朋友跟隨小編一起看看吧2024-02-02
keepalived+lvs 對nginx做負(fù)載均衡和高可用的操作方法
這篇文章主要介紹了keepalived+lvs 對nginx做負(fù)載均衡和高可用的操作方法,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2023-12-12
Nginx多ip部署多站點(diǎn)的實(shí)現(xiàn)步驟
使用Nginx在具有多個(gè)IP地址的服務(wù)器上部署多個(gè)站點(diǎn),從而實(shí)現(xiàn)高效、安全的網(wǎng)站托管,本文主要介紹了Nginx多ip部署多站點(diǎn)的實(shí)現(xiàn)步驟,感興趣的可以了解一下2024-01-01

