热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

ubuntu下nginx启动配置文件

2019独角兽企业重金招聘Python工程师标准在https:github.comJasonGiedyminnginx-init-ubuntu获得的nginx配置文件其中一些

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

在https://github.com/JasonGiedymin/nginx-init-ubuntu获得的nginx配置文件

其中一些位置需要根据实际配置更改

#! /bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: nginx init.d dash script for Ubuntu or other *nix.
# Description: nginx init.d dash script for Ubuntu or other *nix.
### END INIT INFO
#------------------------------------------------------------------------------
# nginx - this Debian Almquist shell (dash) script, starts and stops the nginx
# daemon for Ubuntu and other *nix releases.
#
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server. This \
# script will manage the initiation of the \
# server and it's process state.
#
# processname: nginx
# config: /usr/local/nginx/conf/nginx.conf
# pidfile: /usr/local/nginx/logs/nginx.pid
# Provides: nginx
#
# Author: Jason Giedymin
# .
#
# Version: 3.5.1 11-NOV-2013 jason.giedymin AT gmail.com
# Notes: nginx init.d dash script for Ubuntu.
# Tested with: Ubuntu 13.10, nginx-1.4.3
#
# This script's project home is:
# http://github.com/JasonGiedymin/nginx-init-ubuntu
#
#------------------------------------------------------------------------------
# MIT X11 License
#------------------------------------------------------------------------------
#
# Copyright (c) 2008-2013 Jason Giedymin, http://jasongiedymin.com
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#------------------------------------------------------------------------------#------------------------------------------------------------------------------
# Functions
#------------------------------------------------------------------------------
LSB_FUNC=/lib/lsb/init-functions# Test that init functions exists
test -r $LSB_FUNC || {echo "$0: Cannot find $LSB_FUNC! Script exiting." 1>&2exit 5
}. $LSB_FUNC#------------------------------------------------------------------------------
# Consts
#------------------------------------------------------------------------------
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin #更改此处
DAEMON=/usr/local/nginx/sbin/nginx #更改此处PS="nginx"
PIDNAME="nginx" #lets you do $PS-slave
PIDFILE=$PIDNAME.pid #pid file
PIDSPATH=/usr/local/nginx/logs #default pid location, you should change it更改DESCRIPTION="Nginx Server..."RUNAS=root #user to run asSCRIPT_OK=0 #ala error codes
SCRIPT_ERROR=1 #ala error codes
TRUE=1 #boolean
FALSE=0 #booleanlockfile=/var/lock/subsys/nginx
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf" #如有需要,更改此处#------------------------------------------------------------------------------
# Simple Tests
#------------------------------------------------------------------------------# Test if nginx is a file and executable
test -x $DAEMON || {echo "$0: You don't have permissions to execute nginx." 1>&2exit 4
}# Include nginx defaults if available
if [ -f /etc/default/nginx ]; then. /etc/default/nginx
fi#set exit condition
#set -e#------------------------------------------------------------------------------
# Functions
#------------------------------------------------------------------------------setFilePerms(){if [ -f $PIDSPATH/$PIDFILE ]; thenchmod 400 $PIDSPATH/$PIDFILEfi
}configtest() {$DAEMON -t -c $NGINX_CONF_FILE
}getPSCount() {return `pgrep -f $PS | wc -l`
}isRunning() {if [ $1 ]; thenpidof_daemon $1PID=$?if [ $PID -gt 0 ]; thenreturn 1elsereturn 0fielsepidof_daemonPID=$?if [ $PID -gt 0 ]; thenreturn 1elsereturn 0fifi
}#courtesy of php-fpm
wait_for_pid () {try=0while test $try -lt 35 ; docase "$1" in'created')if [ -f "$2" ]; thentry=''breakfi;;'removed')if [ ! -f "$2" ]; thentry=''breakfi;;esactry=`expr $try + 1`sleep 1done
}status(){isRunningisAlive=$?if [ "${isAlive}" -eq $TRUE ]; thenlog_warning_msg "$DESCRIPTION found running with processes: `pidof $PS`"rc=0elselog_warning_msg "$DESCRIPTION is NOT running."rc=3fireturn
}removePIDFile(){if [ $1 ]; thenif [ -f $1 ]; thenrm -f $1fielse#Do default removalif [ -f $PIDSPATH/$PIDFILE ]; thenrm -f $PIDSPATH/$PIDFILEfifi
}start() {log_daemon_msg "Starting $DESCRIPTION"isRunningisAlive=$?if [ "${isAlive}" -eq $TRUE ]; thenlog_end_msg $SCRIPT_ERRORrc=0elsestart-stop-daemon --start --quiet --chuid \$RUNAS --pidfile $PIDSPATH/$PIDFILE --exec $DAEMON \-- -c $NGINX_CONF_FILEsetFilePermslog_end_msg $SCRIPT_OKrc=0fireturn
}stop() {log_daemon_msg "Stopping $DESCRIPTION"isRunningisAlive=$?if [ "${isAlive}" -eq $TRUE ]; thenstart-stop-daemon --stop --quiet --pidfile $PIDSPATH/$PIDFILEwait_for_pid 'removed' $PIDSPATH/$PIDFILEif [ -n "$try" ]; thenlog_end_msg $SCRIPT_ERRORrc=0 # lsb states 1, but under status it is 2 (which is more prescriptive). Deferring to standard.elseremovePIDFilelog_end_msg $SCRIPT_OKrc=0fielselog_end_msg $SCRIPT_ERRORrc=7fireturn
}reload() {configtest || return $?log_daemon_msg "Reloading (via HUP) $DESCRIPTION"isRunningif [ $? -eq $TRUE ]; thenkill -HUP `cat $PIDSPATH/$PIDFILE`log_end_msg $SCRIPT_OKrc=0elselog_end_msg $SCRIPT_ERRORrc=7fireturn
}quietupgrade() {log_daemon_msg "Peforming Quiet Upgrade $DESCRIPTION"isRunningisAlive=$?if [ "${isAlive}" -eq $TRUE ]; thenkill -USR2 `cat $PIDSPATH/$PIDFILE`kill -WINCH `cat $PIDSPATH/$PIDFILE.oldbin`isRunningisAlive=$?if [ "${isAlive}" -eq $TRUE ]; thenkill -QUIT `cat $PIDSPATH/$PIDFILE.oldbin`wait_for_pid 'removed' $PIDSPATH/$PIDFILE.oldbinremovePIDFile $PIDSPATH/$PIDFILE.oldbinlog_end_msg $SCRIPT_OKrc=0elselog_end_msg $SCRIPT_ERRORlog_daemon_msg "ERROR! Reverting back to original $DESCRIPTION"kill -HUP `cat $PIDSPATH/$PIDFILE`kill -TERM `cat $PIDSPATH/$PIDFILE.oldbin`kill -QUIT `cat $PIDSPATH/$PIDFILE.oldbin`wait_for_pid 'removed' $PIDSPATH/$PIDFILE.oldbinremovePIDFile $PIDSPATH/$PIDFILE.oldbinlog_end_msg $SCRIPT_OKrc=0fielselog_end_msg $SCRIPT_ERRORrc=7fireturn
}terminate() {log_daemon_msg "Force terminating (via KILL) $DESCRIPTION"PIDS=`pidof $PS` || true[ -e $PIDSPATH/$PIDFILE ] && PIDS2=`cat $PIDSPATH/$PIDFILE`for i in $PIDS; doif [ "$i" = "$PIDS2" ]; thenkill $iwait_for_pid 'removed' $PIDSPATH/$PIDFILEremovePIDFilefidonelog_end_msg $SCRIPT_OKrc=0
}destroy() {log_daemon_msg "Force terminating and may include self (via KILLALL) $DESCRIPTION"killall $PS -q >> /dev/null 2>&1log_end_msg $SCRIPT_OKrc=0
}pidof_daemon() {PIDS=`pidof $PS` || true[ -e $PIDSPATH/$PIDFILE ] && PIDS2=`cat $PIDSPATH/$PIDFILE`for i in $PIDS; doif [ "$i" = "$PIDS2" ]; thenreturn 1fidonereturn 0
}action="$1"
case "$1" instart)start;;stop)stop;;restart|force-reload)stop# if [ $rc -ne 0 ]; then# script_exit# fisleep 1start;;reload)$1;;status)status;;configtest)$1;;quietupgrade)$1;;terminate)$1;;destroy)$1;;*)FULLPATH=/etc/init.d/$PSecho "Usage: $FULLPATH {start|stop|restart|force-reload|status|configtest|quietupgrade|terminate|destroy}"echo " The 'destroy' command should only be used as a last resort." exit 3;;
esacexit $rc

将其存为/etc/init.d/nginx,之后修改权限

chmod +x /etc/init.d/nginx

以后启动nginx可用

service nginx start

之后执行

sudo update-rc.d -f nginx defaults



添加开机启动



转:https://my.oschina.net/u/1156611/blog/180659



推荐阅读
  • 本文详细介绍如何在Android模拟器上安装TaintDroid的过程,包括解决源代码链接失效及服务器文件变动等问题,旨在帮助后续用户避免不必要的麻烦。 ... [详细]
  • 导读上一篇讲了zsh的常用字符串操作,这篇开始讲更为琐碎的转义字符和格式化输出相关内容。包括转义字符、引号、print、printf的使用等等。其中很多内容没有必要记忆,作为手册参 ... [详细]
  • Flutter入门指南:实现自动关闭的对话框与提示
    本文为Flutter系列教程的一部分,专注于讲解如何在Flutter应用中实现自动关闭的对话框和提示。通过具体的代码示例,帮助开发者掌握SnackBar、BottomSheet和Dialog的使用方法。 ... [详细]
  • Python图像处理库概览
    本文详细介绍了Python中常用的图像处理库,包括scikit-image、Numpy、Scipy、Pillow、OpenCV-Python、SimpleCV、Mahotas、SimpleITK、pgmagick和Pycairo,旨在帮助开发者和研究人员选择合适的工具进行图像处理任务。 ... [详细]
  • Iris 开发环境配置指南 (最新 Go & IntelliJ IDEA & Iris V12)
    本指南详细介绍了如何在最新的 Go 语言环境及 IntelliJ IDEA 中配置 Iris V12 框架,适合初学者和有经验的开发者。文章提供了详细的步骤说明和示例代码,帮助读者快速搭建开发环境。 ... [详细]
  • 本文详细记录了在Ubuntu 9.10操作系统上从零开始搭建LAMP(Linux, Apache, MySQL, PHP)环境的过程,包括遇到的问题及解决方案。旨在为初次尝试搭建LAMP环境的开发者提供参考。 ... [详细]
  • OpenWrt 是一款高度可定制的嵌入式 Linux 发行版,广泛应用于无线路由器等领域,拥有超过百个预装软件包。本文详细探讨如何在 OpenWrt 上通过 Luci 构建自定义模块,以扩展其功能。 ... [详细]
  • Python作为一种广泛使用的高级编程语言,以其简洁的语法、强大的功能和丰富的库支持著称。本文将详细介绍Python的主要特点及其在现代软件开发中的应用。 ... [详细]
  • 手把手教你构建简易JSON解析器
    本文将带你深入了解JSON解析器的构建过程,通过实践掌握JSON解析的基本原理。适合所有对数据解析感兴趣的开发者。 ... [详细]
  • SonarQube配置与使用指南
    本文档详细介绍了SonarQube的配置方法及使用流程,包括环境准备、样本分析、数据库配置、项目属性文件解析以及插件安装等内容,适用于具有Linux基础操作能力的用户。 ... [详细]
  • 本文基于https://major.io/2014/05/13/coreos-vs-project-atomic-a-review/的内容,对CoreOS和Atomic两个操作系统进行了详细的对比,涵盖部署、管理和安全性等多个方面。 ... [详细]
  • Flutter 高德地图插件使用指南
    本文档详细介绍了如何在Flutter项目中集成和使用高德地图插件,包括安装、配置及基本使用方法。 ... [详细]
  • WorldWind源代码解析:瓦片调度机制详解
    本文深入探讨了WorldWind项目中的关键组件——瓦片调度策略。通过源代码分析,我们将了解摄像头移动时如何动态调整瓦片的加载与卸载,确保地图渲染的高效与流畅。 ... [详细]
  • scrapyredis分布式爬虫 ... [详细]
  • QEMU环境下加载首个Linux驱动模块
    本文介绍了如何在Ubuntu 20.04系统上使用QEMU虚拟机加载一个简单的Linux驱动模块。此过程涉及Linux内核4.0版本的配置与编译。 ... [详细]
author-avatar
加乘ACCA财务英语教室_438
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有