Linux下创建nginx脚本-start、stop、reload…
发布:smiling 来源: PHP粉丝网 添加日期:2021-03-28 21:07:45 浏览: 评论:0
这篇文章主要介绍了Linux下创建nginx脚本-start、stop、reload的方法,需要的朋友可以参考下
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
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#
 
注:/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
 
Tags: nginx start stop reload
- 上一篇:Linux下手动编译安装PHP扩展的例子分享
 - 下一篇:linux中cd命令使用详解
 
相关文章
- ·monit配置监控启动nginx php mysql redis mongodb 服务器(2014-10-01)
 - ·linux中Nginx Rewrite规则工作笔记(2014-10-01)
 - ·Linux中利用openssl生成SSL证书给nginx使用(2014-10-11)
 - ·linux中编译Nginx支持Tcp_wrappers方法(2014-10-12)
 - ·linux中修改Nginx For Tcp_wrappers返回444(2014-10-12)
 - ·linux中配合php实现Nginx反向代理(2014-10-13)
 - ·linux中Nginx的常用配置(域名跳转 https cdn配置)(2014-10-13)
 - ·阿里云linux服务器配置安装nginx(2014-10-13)
 - ·linux中Nginx与Lua执行顺序详解(2014-10-14)
 - ·linux系统中Nginx守护进程(自动启动nginx)(2014-10-15)
 - ·linux中nginx下禁止某目录执行php例子(2014-10-16)
 - ·linux系统nginx php-fpm安装php memcache扩展(2014-10-17)
 - ·Apache与Nginx登录认证配置详解(可认证目录)(2014-10-17)
 - ·linux+nginx+php+mysql环境查找php.ini文件并修改(2014-10-18)
 - ·Nginx下proxy_set_header 模块代码(2015-04-21)
 - ·linux下Shell脚本分析Nginx日志抗小量ddos攻击(2015-04-21)
 
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
 - PHP新手上路(一)(7)
 - 惹恼程序员的十件事(5)
 - PHP邮件发送例子,已测试成功(5)
 - 致初学者:PHP比ASP优秀的七个理由(4)
 - PHP会被淘汰吗?(4)
 - PHP新手上路(四)(4)
 - 如何去学习PHP?(2)
 - 简单入门级php分页代码(2)
 - php中邮箱email 电话等格式的验证(2)
 
