Should work on RHEL, Fedora, CentOS. Tested on CentOS 5.
Save this file as /etc/init.d/nginx
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/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/sbin/nginx"
prog
=$(
basename
$nginx
)
NGINX_CONF_FILE
="/etc/nginx/nginx.conf"
[
-f
/
etc/
sysconfig/
nginx ]
&&
. /
etc/
sysconfig/
nginx
lockfile
=/
var/
lock/
subsys/
nginx
make_dirs(
)
{
# make required directories
user
=`
$nginx
-V
2
>&
1
|
grep
"configure arguments:"
|
sed
's/[^*]*--user=\([^ ]*\).*/\1/g'
-`
if
[
-z
"`grep $user /etc/passwd`
"
]
; then
useradd -M
-s
/
bin/
nologin $user
fi
options
=`
$nginx
-V
2
>&
1
|
grep
'configure arguments:'
`
for
opt in
$options
; do
if
[
`
echo
$opt
|
grep
'.*-temp-path'
`
]
; then
value
=`
echo
$opt
|
cut
-d
"="
-f
2
`
if
[
!
-d
"$value
"
]
; then
# echo "creating" $value
mkdir
-p
$value
&&
chown
-R
$user
$value
fi
fi
done
}
start(
)
{
[
-x
$nginx
]
||
exit
5
[
-f
$NGINX_CONF_FILE
]
||
exit
6
make_dirs
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
sleep
1
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
分享到:
相关推荐
linux安装nginx依赖包,该报包含了openssl和pcre和zlib,软件版本为openssl-fips-2.0.12.tar.gz、pcre-8.21.tar.gz、zlib-1.2.11.tar.gz
windows环境下nginx init脚本示例 包含启动及关闭示例
linux系统上 nginx自动安装的shell脚本 能自动适配系统版本
NULL 博文链接:https://km-moon11.iteye.com/blog/1870851
前端Nginx主备,负载均衡。 两台应用服务器每台都与负载均衡器相连,负载均衡器分配WEB请求到应用服务器。两台负载均衡器对外提供单一IP地址WEB服务; 通过heartbeat管理故障切换集群中可用的负载均衡分配器nginxd...
vi /etc/init.d/nginx 修改nginx后 chmod +x /etc/init.d/nginx /sbin/chkconfig nginx on sudo /sbin/chkconfig --list nginx /etc/init.d/nginx start
nginx-init-ubuntu, 尝试和 true Nginx 初始化脚本得到增强 发送请求? ! nginx-init-ubuntu状态 当前版本:v3.9.0以前稳定版本 v3.8.0注意:v3.8.0在最近几个月一直稳定,没有问题。 v3.9.0稳定,是新的。电子邮件...
这个压缩包里面包含了在openwrt交叉编译nginx-1.8.0所需要的Makefile和patch。 作为文章http://blog.csdn.net/ping1214/article/details/45397729的附件。
ubuntu /etc/init.d/nginx
# nginx Startup script for nginx # # chkconfig: - 85 15 # processname: nginx # config: /etc/nginx/nginx.conf # config: /etc/sysconfig/nginx # pidfile: /var/run/nginx.pid # description: nginx is a ...
该安装包为nginx离线安装所需要的所有离线包,使用方式tar -zxvf rmp.tar.gz 进入解压后的目录下执行 cd rmp; rpm -Uvh ./*.rpm --nodeps –force
系统环境:CentOS6、CentOS7、Red Hat6、Red Hat7 软件:nginx-1.16.0.tar.gz 其他所需软件:openssl-1.0.2s.tar.gz、pcre-8.37.tar.gz、zlib-1.2.8.tar.gz 安装方式:源码编译安装 安装位置:/usr/local/nginx ...
nginx容器:Nginx高性能HTTP服务器和基于Red Hat Software Collections的反向代理容器映像,旨在用于OpenShift和一般用途。 用户可以在基于Red Hat Enterprise Linux,Fedora和CentOS的映像之间进行选择
nginx 日志按日切分,定时清理过期日志信息,防止占用大量磁盘空间,可访问该地址查询:https://blog.csdn.net/qq_39291929/article/details/107676337
本文主要是springboot前后端分离项目linux打包运行环境搭建过程,包含jdk、mysql、redis、nginx的环境搭建全过程
本剧本将安装 Nginx + nginx-init-ubuntu。 变量 使用上面提到的 ansible 角色时,您需要将nginx_docker_override设置为True因为该角色将检测是否在 Dockerfile 中运行。 这是为了防止 nginx 在daemon模式下运行。 ...
在/etc/init.d下创建文件nginx [root@localhost ~]# vim /etc/init.d/nginx 其内容参考nginx官方文档 需要注意的配置: nginx=”/usr/local/nginx/sbin/nginx” //修改成nginx执行程序的路径。 NGINX_CONF_FILE=”/...
nginx 离线安装包nginx 离线安装包
(1)原理 基于nginx提供的状态信息页面解析 ...(2)部署配置(客户端) 1)配置nginx 在对应server中添加状态信息页面location,启动状态...UserParameter=res_code[*],/usr/local/zabbix/script/nginx_logs.py $1
慕名对nginx的源码进行学习研究是早在2009年的事情,当时还在学校,整天... gcc gcc version 4.4.6 20110731 (Red Hat 4.4.6-3) (GCC) gdb GNU gdb (GDB) Red Hat Enterprise Linux (7.2-50.el6) make GNU Make 3.81