热门标签 | 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



推荐阅读
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社区 版权所有