#!/bin/sh
# 作者:jims
# 描述 : 开启停止 nginx 的脚本
NGINX_DIR=/usr/local/nginx #nginx的安装路径
export NGINX_DIR #输入到环境变量中
case $1 in
'start' )
echo "Starting nginx..."
$NGINX_DIR/sbin/nginx
echo "Start Ok."
;;
'restart' )
echo "Restarting nginx ..."
kill -HUP `cat $NGINX_DIR/logs/nginx.pid` #平滑重启
echo "Restart Ok."
;;
'stop' )
echo "Stopping nginx..."
kill -15 `cat $NGINX_DIR/logs/nginx.pid`
echo "Stop Ok"
;;
'testcfg' )
$NGINX_DIR/sbin/nginx -t
;;
*)
echo "参数: `basename $0` {start|restart|stop||testcfg}"
esac
可以把文件放入到/usr/bin目录下,方便对nginx的基本操作。
网络转载一个可以放入chkconfig中的。
#!/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
分享到:
相关推荐
docker安装mysql、redis、nginx shell脚本
自动化部署Nginx Shell脚本
搭建nginx,安装包去官网下载,然后修改脚本路径,执行即可
本解本实现了使用shell脚本实现nginx日志分割,大家如果没资源分下载,可以转至:https://mp.csdn.net/mdeditor/85233117# 去查看源代码。谢谢大家
nginx自动化安装shell脚本
监控生产环境nginx日志发告警邮件,需要使用linux系统的定时任务,如5分钟执行或者其他时间间隔
原文链接:https://blog.csdn.net/m0_37814112/article/details/119391879?spm=1001.2014.3001.5501 说明:一键生产nginx https自签证书脚本,真实有效!
nginx实现请求的负载均衡 + keepalived实现nginx的高可用的shell脚本,在liunx下跑就可以
将其复制到/etc/init.d下。 就可以通过service nginx start | restart | stop 管理nginx了
ubuntu自动安装nginx php脚本ubuntu自动安装nginx php脚本
常用shell脚本, Dos攻击防范(自动屏蔽攻击IP).sh 一键部署等等 Linux系统发送告警脚本.sh MySQL数据库备份单循环.sh MySQL数据库备份多循环.sh nginx 访问访问日志按天切割.sh nginx.conf nginx访问日志分析...
CentOS7 自动化搭建Nginx+PHP7+Mysql+Docker+Docker-Compose Shell脚本,Docker version 18.06.1-ce,docker-compose version 1.22.0
nginx一键部署,包含shell脚本及nginx安装包
Nginx日志自动归档备份shell脚本log
CentOS 一键安装PostgreSQL10.2 shell脚本,脚本中已表明可更改版本的位置
使用shell脚本,使其直接在centos7下直接部署nginx和php,成功访问phpinfo
通过编写shell脚本定时比对新老IP自动对nginx进行reload有效解决了nginx对动态域名不重新解析的问题,附带详细说明
下面分享一下我用Shell编写的分析Nginx日志的脚本,它可以快速得出排名最前的网 站和IP等,内容如下所示: Most of the ip: ------------------------------------------- 220 59.41.24.48 178 59.41.24.80 172 ...
php管理nginx虚拟主机shell脚本_.docx