Nginx手動啟動
停止操作
停止操作是通過向nginx進程發送信號(什么是信號請參閱linux文 章)來進行的步驟1:查詢nginx主進程號ps -ef | grep nginx在進程列表里 面找master進程,它的編號就是主進程號了。步驟2:發送信號從容停止Nginx:kill -QUIT 主進程號快速停止Nginx:kill -TERM 主進程號強制停止Nginx:pkill -9 nginx
另外, 若在nginx.conf配置了pid文件存放路徑則該文件存放的就是Nginx主進程號,如果沒指定則放在nginx的logs目錄下。有了pid文 件,我們就不用先查詢Nginx的主進程號,而直接向Nginx發送信號了,命令如下:kill -信號類型 '/usr/nginx/logs/nginx.pid'
命令:/usr/local/nginx/sbin/nginx
若出現:
[root@kangxiaowei ~]# /usr/local/nginx/sbin/nginx[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)[emerg]: still could not bind()
則再次執行 /root/lnmp stop關閉lnmp即可
Nginx的開機啟動腳本
開機自動啟動nginx,
如果需要開機啟動服務,保存好 /etc/init.d/nginx文件后,
執行以下命令:
代碼如下 復制代碼 chkconfig --add ningx
chkconfig --level nginx 2345 on
開機自動啟動腳本
代碼如下 復制代碼 #! /bin/sh# chkconfig: 2345 55 25# Description: Startup script for nginx webserver on Debian. Place in /etc/init.d and# run 'update-rc.d -f nginx defaults', or use the apPRopriate command on your# distro. For CentOS/Redhat run: 'chkconfig --add nginx'
### BEGIN INIT INFO# Provides: nginx# Required-Start: $all# Required-Stop: $all# Default-Start: 2 3 4 5# Default-Stop: 0 1 6# Short-Description: starts the nginx web server# Descri(www.111cn.net)ption: starts nginx using start-stop-daemon### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/binDESC="nginx daemon"NAME=nginxDAEMON=/usr/local/platform/nginx/sbin/$NAMECONFIGFILE=/usr/local/platform/nginx/conf/$NAME.confPIDFILE=/usr/local/platform/nginx/logs/$NAME.pidSCRIPTNAME=/etc/init.d/$NAME
set -e[ -x "$DAEMON" ] || exit 0
do_start() { $DAEMON -c $CONFIGFILE || echo -n "nginx already running"}
do_stop() { kill -INT `cat $PIDFILE` || echo -n "nginx not running"}
do_reload() { kill -HUP `cat $PIDFILE` || echo -n "nginx can't reload"}
case "$1" in start) echo -n "Starting $DESC: $NAME" do_start echo "." ;; stop) echo -n "Stopping $DESC: $NAME" do_stop echo "." ;; reload|graceful) echo -n "Reloading $DESC configuration..." do_reload echo "." ;; restart) echo -n "Restarting $DESC: $NAME" do_stop do_start echo "." ;; *) echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2 exit 3 ;;esac
exit 0
需要你修改的配置有
代碼如下 復制代碼 #! /bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=nginxDAEMON=/usr/local/nginx/sbin/$NAMECONFIGFILE=/usr/local/nginx/conf/$NAME.confPIDFILE=/usr/local/nginx/logs/$NAME.pid
編輯好后保存,執行以下命令
代碼如下 復制代碼 1 chmod +x /etc/init.d/nginx
現在把Nginx加入chkconfig,并設置開機啟動。
代碼如下 復制代碼 12 chkconfig --add nginx chkconfig nginx on
# 檢查一下
代碼如下 復制代碼 1 chkconfig --list nginx nginx 0:off 1:off 2:on 3:on 4:on 5:on 6:off from:http://www.111cn.net/sys/nginx/52908.htm
新聞熱點
疑難解答