Linux下创建nginx脚本-start、stop、reload…
2015-01-24信息快讯网
这篇文章主要介绍了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
thinkphp中session和cookie无效的解决方法
thinkphp3.0输出重复两次的解决方法
thinkphp3.2.2实现生成多张缩略图的方法
ThinkPHP打开验证码页面显示乱码的解决方法
ThinkPHP中使用ajax接收json数据的方法
PHP提示Warning:phpinfo() has been disabled函数禁用的解决方法
phpmyadmin提示The mbstring extension is missing的解决方法
php提示Warning:mysql_fetch_array() expects的解决方法
php使用pdo连接报错Connection failed SQLSTATE的解决方法
PHP缓存集成库phpFastCache用法
phpstorm配置Xdebug进行调试PHP教程
phpstorm编辑器乱码问题解决
php中ob_get_length缓冲与获取缓冲长度实例
php管理nginx虚拟主机shell脚本实例
叫你如何修改Nginx与PHP的文件上传大小限制
PHP+FastCGI+Nginx配置PHP运行环境
linux下安装php的memcached客户端
Linux下php5.4启动脚本
linux下编译安装memcached服务
php mb_substr()函数截取中文字符串应用示例
PHP实现把文本中的URL转换为链接的auolink()函数分享
Win2003+apache+PHP+SqlServer2008 配置生产环境
windows的文件系统机制引发的PHP路径爆破问题分析
PHP错误Allowed memory size of 67108864 bytes exhausted的3种解决办法
浅析get与post的一些特殊情况
PHP中file_exists函数不支持中文名的解决方法
PHP中可以自动分割查询字符的Parse_str函数使用示例
php实现与erlang的二进制通讯实例解析
PHP实现生成透明背景的PNG缩略图函数分享
PHP的error_reporting错误级别变量对照表
PHP使用range协议实现输出文件断点续传代码实例
ThinkPHP模板范围判断输出In标签与Range标签用法详解
PHP统计nginx访问日志中的搜索引擎抓取404链接页面路径
php调用nginx的mod_zip模块打包ZIP文件
PHP、Nginx、Apache中禁止网页被iframe引用的方法
PHP加Nginx实现动态裁剪图片方案