Nginx快捷启动配置
Linux下Nginx开关服务,正常方式是这样({nginx}-为Nginx安装路径):
- {nginx}/sbin/nginx #启动
- {nginx}/sbin/nginx -s stop #停止
这种方式带来很多不便,因此介绍一种快捷启动关闭Nginx的方式。
在/etc/init.d下创建nginx启动脚本文件:
- vim /etc/init.d/nginx
i进入编辑状态,粘贴以下代码后保存:
将/usr/local/nginx/替换为自身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/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
- [ $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
- 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 2
- esac
修改脚本权限:
- chmod 755 nginx
将脚本文件加入到chkconfig中:
- chkconfig --add nginx
设置nginx开机在3和5级别自动启动:
- chkconfig --level 35 nginx on
创建软连接:
- cd /usr/bin
- ln -s /etc/init.d/nginx
愉快的玩耍吧!
这里边的命令都可以执行:
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
以下是示例:
- nginx start
- nginx stop
- nginx restart
Nginx快捷启动配置的更多相关文章
- CentOS下nginx+php的配置及nginx开机启动配置
关闭防火墙 (不然外链接是访问不了 apache) service iptables stop 关闭安全系统 SELinux( 不然报403 访问页面错误 ) 1.Nginx安装主要在于配置文件的修改 ...
- windows nginx 快捷启动关闭批处理脚本
:: 关闭回显,即执行本脚本时不显示执行路径和命令,直接显示结果 @echo off rem @author luwuer color f8 set NGINX_DIR=D:\nginx-1.12.2 ...
- nginx入门与实战 安装 启动 配置nginx Nginx状态信息(status)配置 正向代理 反向代理 nginx语法之location详解
nginx入门与实战 网站服务 想必我们大多数人都是通过访问网站而开始接触互联网的吧.我们平时访问的网站服务 就是 Web 网络服务,一般是指允许用户通过浏览器访问到互联网中各种资源的服务. Web ...
- Nginx使用(配置开机启动)
环境: 系统:CentOS 6.5 Final 安装目录:/usr/local/nginx Nginx开机自启: ①编写shell实现控制 vi /etc/init.d/nginx 添加内容: #!/ ...
- 04-Uwsgi配置启动Nginx虚拟主机配置
一.虚拟环境的安装 1.安装虚拟环境 sudo pip3 install virtualenv 2.安装virtualenvwrapper sudo pip3 install virtualenvwr ...
- 【Linux】宝塔上 GitLab数据迁移修改配置后nginx无法启动
背景: 服务器A 向 服务器B 迁移数据,修改配置重启.发现gitlab的 nginx 无法启动. 查找原因 gitlab-ctl tail 错误信息: 网上查了查,似乎是宝塔的问题, 原因应该是为了 ...
- 安装nginx并安全地配置和启动
一.安装nginx >>参考文章<< 安装教程,看代码&注释 # .sh # 如果centos服务器是最低安装,则先安装weget yum install -y wge ...
- nginx学习与配置-安装与启动关闭管理
nginx服务器的安装 安装准备: nginx依赖于pcre库,要先安装pcre yum install pcre pcre-devel cd /usr/local/src/ wget wget ht ...
- Nginx使用默认配置启动异常处理
Ps1:错误问题:nginx: [error] OpenEvent("Global\ngx_reload_5988") failed (2: The system cannot f ...
随机推荐
- java学习之—链表(2)
/** * 双端链表操作 * Create by Administrator * 2018/6/14 0014 * 下午 2:05 **/ class Link1 { public long dDat ...
- Prism框架研究(二)
首先在介绍本节内容之前,首先来看看官方文档来如何描述Prism 应用的初始化吧!A Prism application requires registration and configuration ...
- mysql从入门到精通
解决MySQL Got a packet bigger than 'max_allowed_packet' bytes 问题在一次性向mysql插入的数据过大,可在my.ini中修改max_allow ...
- vue-cli: preset预设
preset:预设 vue create demo01 过程中,会保存预设,自动保存着 .vuerc 文件中 .vuerc 文件的位置:C:\Users\Administrator C:\Users\ ...
- SQL Server 数据库try catch 存储过程
SQL Server 在生产环境中这样写存储过程的坑都避免了吗? 原文链接: http://www.cnblogs.com/chenmh/p/7856777.html 概述 最近因为业务的需求写了一段 ...
- How to install macOS Sierra on Skylake
create usb installer sudo /Applications/Install\ macOS\ Sierra.app/contents/resources/createinstallm ...
- 【C/C++】实现牛顿迭代
#include<bits/stdc++.h> using namespace std; /*(x+2)^2 +1 -2(x-1)^2+7 */ double f(double x){ - ...
- JSON 解析 (二)—— Jackson的使用
Jackson是基于Java语言的一种JSON和Java对象的数据处理工具.功能上简单易用,性能上根据目前主流转换工具比较,Jackson相对比较高效. <dependency> < ...
- Go语言类型(布尔、整型、数组、切片、map等)
1.基本类型 布尔类型:bool 注意:布尔类型不能接受其他类型的赋值,不支持自动或强制的类型转换. 整型:int8.byte(uint8).int16.int.uint.uintptr int.ui ...
- kubernetes 构架