在centos中创建nginx启动脚本

1. 建立脚本文件nginxd

[[email protected]]# vi /etc/init.d/nginxd

插入以下内容

#!/bin/bash
#
# chkconfig: - 85 15
# description: Nginx is a World Wide Web server.
# processname: nginx

nginx=/usr/local/nginx/sbin/nginx
conf=/usr/local/nginx/conf/nginx.conf
case $1 in
start)
echo -n "Starting Nginx"
$nginx -c $conf
echo " done"
;;
stop)
echo -n "Stopping Nginx"
killall -9 nginx
echo " done"
;;
test)
$nginx -t -c $conf
;;
reload)
echo -n "Reloading Nginx"
ps auxww | grep nginx | grep master | awk ‘{print $2}‘ | xargs kill -HUP
echo " done"
;;
restart)
$0 stop
$0 start
;;
show)
ps -aux|grep nginx
;;
*)
echo -n "Usage: $0 {start|restart|reload|stop|test|show}"
;;
esac

2、更改nginxd权限

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

3、设置开机启动

[[email protected]]# chkconfig nginxd on

时间: 2024-08-26 17:33:52

在centos中创建nginx启动脚本的相关文章

nginx启动脚本编写及设置开机自启动

环境:Centos 6.8 如果机器是Centos 7的,此脚本和设置开机自启动方法不适用. 首先确保nginx配置文件中:有pid目录 pid        logs/nginx.pid; 1.1 编写nginx启动脚本 [[email protected] ~]# cd /server/scripts [[email protected] scripts]# vim nginx.sh  #!/bin/bash [ -f /etc/init.d/functions ] && . /etc

简单的nginx启动脚本

初学时写的一个简单nginx启动脚本,使用定义函数和传参的方法.(生产环境中是不能用pkill来杀服务的,要使用-s reload来平滑重启) [[email protected]]# cat start_nginx04.sh #!/bin/sh ./etc/init.d/functions start_nginx=/nginx/sbin/nginx USAGE(){ echo "USAGE $0{start|stop|restart}" exit 1 } if [ $# -ne 1

Nginx启动脚本大家来找茬

今天讲到shell编程,我给大家讲解手工开发Nginx启动脚本时,写的脚本,调试发现有问题, 挺有意思的一个问题点,有2个地方有影响启动和停止的问题,有兴趣的可以研究下, 一周后公布结果! [[email protected] 03]# cat nginxd-good  #!/bin/sh RETVAL=0 path="/application/nginx" . /etc/init.d/functions start(){ if [ ! -f "$path/logs/ngin

Linux学习篇之---centos中的开机自启动脚本

centos中的开机自启动脚本 在cenos环境下,安装jdk,需要配置环境变量,网上有人说: 1.直接将语句写入/etc/profile中 2.将语句写入一个java.sh文件,然后将文件放到/etc/profile.d/目录下 现在看一下/etc/profile文件中内容: 其实这两种效果是一样的,/etc/profile文件执行的时候会遍历/etc/profile.d/目录下的所有*.sh文件,并依次执行. 但是个人认为还是使用后者比较好: 因为如果用得着,就新建一个.sh文件,如果用不着

CentOS中实现Nginx负载均衡和反向代理

一.安装必要软件 负载均衡服务器:IP设置为192.168.1.10 Web服务器1:安装Apache或者Nginx,IP设置为192.168.1.11: Web服务器2:安装Apache或者Nginx,IP设置为192.168.1.12. 二.配置负载均衡服务器 1.在Nginx的conf目录下新建extra文件夹,并在其下边编辑生成一个配置文件,比如t_servers.conf upstream test_servers { server 192.168.1.11:80 weight=5;

centos 7 nginx启动脚本

centos7使用systemd代替之前的systemv的启动脚本,可以说更简单.不再需要编写一长段脚本. 复制以下内容到/usr/lib/systemd/system/nginx.service [Unit] Description=nginx - high performance web server Documentation=http://nginx.org/en/docs/ After=network.target remote-fs.target nss-lookup.target

LNMP搭建4:Nginx启动脚本和配置文件

Nginx没有像apachetl那样的启动脚本,我们需要手动做一个 [[email protected] html]# vim /etc/init.d/nginx 内容如下:http://www.apelearn.com/study_v2/chapter18.html #!/bin/bash # chkconfig: - 30 21 # description: http service. # Source Function Library . /etc/init.d/functions # N

LNMP的Nginx启动脚本和配置文件

配置LNMP完成安装,并把PHP也解析完成,但是Nginx启动使用的是一个可执行文件:/usr/local/nginx/sbin/nginx 来启动,非常不方便,要给Nginx写一个启动脚本,同Apache,虽然Apache的启动脚本没有放到/etc/init.d目录下,但Apache有个非常方便的启动.重启.停止脚本,即:"apachectl",而Nginx没有这样的工具, 我们需要手动制作一个启动脚本,如下: [[email protected] ~]# vim /etc/init

解决Nginx启动脚本在redhat上不兼容问题

我们在网上看到的Nginx的启动脚本通常是/etc/rc.d/init.d/nginx这个脚本,其内容是: #!/bin/bash # nginx Startup script for the Nginx HTTP Server # it is v.1.3.0 version. # chkconfig: - 85 15 # description: Nginx is a high-performance web and proxy server. #              It has a