Create nginx scripts under Linux-start, stop, reload..., nginx-start_PHP tutorial

WBOY
Release: 2016-07-13 10:21:31
Original
1312 people have browsed it

Linux下创建nginx脚本-start、stop、reload…,nginx-start

1、关闭nginx
利用ps -aux | grep nginx 查看nginx是否启动 如果启动了就kill杀死
2、创建/etc/init.d/nginx文件

root@dnnp:~/software/nginx-1.2.3# vim /etc/init.d/nginx
Copy after login

3、添加权限并启动

root@dnnp:~/software/nginx-1.2.3# chmod +x /etc/init.d/nginx
root@dnnp:~/software/nginx-1.2.3# /etc/init.d/nginx start
Starting nginx: nginx.
root@dnnp:~/software/nginx-1.2.3# ps -aux | grep nginx
Warning: bad ps syntax, perhaps a bogus '-'? See http://procps.sf.net/faq.html
root   25078 0.0 0.0  4596  700 ?    Ss  14:20  0:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody  25079 0.0 0.1  4820 1056 ?    S  14:20  0:00 nginx: worker process
root   25081 0.0 0.0  3304  768 pts/0  S+  14:20  0:00 grep nginx
root@dnnp:~/software/nginx-1.2.3#
Copy after login

注:/etc/init.d/nginx文件内容如下

#! /bin/sh
 
### 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
# Description:    starts nginx using start-stop-daemon
### END INIT INFO
 
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/nginx/sbin/nginx
NAME=nginx
DESC=nginx
 
test -x $DAEMON || exit 0
 
# Include nginx defaults if available
if [ -f /etc/default/nginx ] ; then
  . /etc/default/nginx
#    . /usr/local/nginx/conf
fi
 
set -e
 
. /lib/lsb/init-functions
 
case "$1" in
 start)
  echo -n "Starting $DESC: "
  start-stop-daemon --start --quiet --pidfile /usr/local/nginx/logs/$NAME.pid \
    --exec $DAEMON -- $DAEMON_OPTS || true
  echo "$NAME."
  ;;
 stop)
  echo -n "Stopping $DESC: "
  start-stop-daemon --stop --quiet --pidfile /usr/local/nginx/logs/$NAME.pid \
    --exec $DAEMON || true
  echo "$NAME."
  ;;
 restart|force-reload)
  echo -n "Restarting $DESC: "
  start-stop-daemon --stop --quiet --pidfile \
    /usr/local/nginx/logs/$NAME.pid --exec $DAEMON || true
  sleep 1
  start-stop-daemon --start --quiet --pidfile \
    /usr/local/nginx/logs/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS || true
  echo "$NAME."
  ;;
 reload)
   echo -n "Reloading $DESC configuration: "
   start-stop-daemon --stop --signal HUP --quiet --pidfile /usr/local/nginx/logs/$NAME.pid \
     --exec $DAEMON || true
   echo "$NAME."
   ;;
 status)
   status_of_proc -p /usr/local/nginx/logs/$NAME.pid "$DAEMON" nginx && exit 0 || exit $?
   ;;
 *)
  N=/etc/init.d/$NAME
  echo "Usage: $N {start|stop|restart|reload|force-reload|status}" >&2
  exit 1
  ;;
esac
 
exit 0
Copy after login

linux下怎重启nginx

在nginx的早期版本,nginx重启需要通过kill命令向nginx发送信号来实现nginx的重启。
但是,现在,nginx增加了-s选项,实现nginx的停止,重新加载功能。
1. 如果是平滑的重启nginx,可以用./nginx -s reload命令实现nginx的平滑重启。
2. 如果是非平滑重启,则可以先停止nginx,然后再启动:
./nginx -s stop && ./nginx

当我们修改nginx配置后,希望重启nginx以便让nginx生效,此时为了保证nginx在重启阶段还能够提供正常的服务,一般采用平滑重启的方式(reload)重启nginx。此时,nginx会加载新的配置,然后fork出新的worker进程。同时,master进程会向老的worker进程发送信号,告诉老的worker进程当前的情况。老的worker进程受到master进程的信号后,如果当时没有处理请求则会退出,如果正在处理请求,则老的worker进程会处理完请求然后退出。nginx就是通过这种方式去reload新的配置,从而使得在重启的过程中,仍然可以提供服务。
 

重启 nginx ,出现该命令,接下来输入什命令

start 启动服务 stop 停止服务 reload 重读配置 restart 重启服务
 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/856991.htmlTechArticleLinux下创建nginx脚本-start、stop、reload…,nginx-start 1、关闭nginx 利用ps -aux | grep nginx 查看nginx是否启动 如果启动了就kill杀死 2、创建/etc/init...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!