nginx添加系统服务(start|stop|restart)

nginx添加系统服务



1、编写脚本,名为nginx

#!/bin/sh

#

#nginx - this script start 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/local/nginx/sbin/nginx"

prog=$(basename $nginx)

NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"

[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx

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

return $retval

}

stop() {

echo -n $"Stopping $prog: "

killproc $prog -QUIT

retval=$?

echo

[ $retval -eq 0 ] && rm -f $lockfile

return $retval

killall -9 nginx

}

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

esac

2、

[[email protected] ~]# cp nginx /etc/init.d/

[[email protected] ~]# chmod 755 /etc/init.d/nginx

[[email protected] ~]# chkconfig --add nginx

3、nginx启动、停止、无间断服务重启

[[email protected] ~]# service nginx start

[[email protected] ~]# service nginx stop

[[email protected] ~]# service nginx reload

完毕


时间: 2024-08-06 11:53:17

nginx添加系统服务(start|stop|restart)的相关文章

CentOS7.4 Nginx添加系统服务及开机自启动

Nginx安装好后,每次启动或者重启需要进入到/usr/local/nginx下操作,比较麻烦,于是把Nginx添加到系统服务中方便管理: # 添加nginx.service # vim /lib/systemd/system/nginx.service [Unit] Description=nginx service After=network.target [Service] Type=forking # 路径对应安装路径 ExecStart=/usr/local/nginx/sbin/ng

nginx添加系统服务

1.在/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: n

阿里云服务器cent0S安装web环境PHP+MySql+Nginx,给nginx添加网站

下载一键安装包: http://market.aliyun.com/product/12-121590002-cmgj000262.html?spm=5176.7150518.1996836753.5.ZoE32o 在服务器安装rz命令 yum install lrzsz rz    选择要上传文件sh.zip 安装解压命令: yum install unzip    #本机已经安装了.所以这里不安装 解压 unzip -x sh.zip    #解压后脚本的权限不够 chmod -R 755

centos7 安装 iRedmail 后 给nginx添加虚拟主机

iRedmail安装参考官方文档和 https://ywnz.com/linuxyffq/4563.html 准备工作 更新操作系统 yum update -y 安装必要组件 yum install perl perl-core ntpl nmap sudo libidn gmp libaio libstdc++ unzip sysstat wget nc -y 停止任何安装在该Centos7 Server上面的 MTA服务 systemctl stop postfix systemctl di

Nginx添加Content-MD5头部压测分析

此文转载必须注明原文地址,请尊重作者的劳动成果! 1.1 Webbench是知名的网站压力测试工具,它是由Lionbridge公司(http://www.lionbridge.com)开发.Webbench能测试处在相同硬件上,不同服务的性能以及不同硬件上同一个服务的运行状况.webbench的标准测试可以向我们展示服务器的两项内容:每秒钟相应请求数和每秒钟传输数据量.webbench不但能具有便准静态页面的测试能力,还能对动态页面(ASP,PHP,JAVA,CGI)进 行测试的能力.还有就是他

将nginx加入系统服务

编写脚本 1,vi /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/ngi

nginx添加sticky模块-cookie保持会话

cookie不同于session,一个存于客户端,一个存于服务端. 环境nginx 1.8.0 centos6.X sticky:1.2.5  wget https://bitbucket.org/nginx-goodies/nginx-sticky-module-ng/get/master.tar.gz cookie负载均衡相比iphash来比其中一个特点比较明显:内网nat用户的均衡.而iphash无法做到. yum install openssl openssl-devel 先停止ngin

Nginx添加到windows服务

在windows平台,把Nginx注册到服务,又可以启动.停止和重启的方法,网上并没找到好的办法. 既然如此,唯有自己写程序实现了 使用C#进行编写,有兴趣的可以下载源码自己改:源码下载 或直接下载编译好的程序,需要.net framework 2.0或.net framework 4.0的环境支持 下载:程序下载 功能说明,使用自己定义的bat脚本,实现自定义windows服务,应该可用于绝大多数像nginx等这类不方便使用windows服务的程序 目录结构及说明: install.bat :

nginx添加ssl模块

原已经安装好的nginx,现在需要添加一个未被编译安装的ssl模块: nginx -V 可以查看原来编译时都带了哪些参数 原来的参数:--prefix=/app/nginx 添加的参数: --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module 步骤如下: 1. 使用参数重新配置: ./configure --prefix=/app/nginx -user=nobody -group=nobod