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



推荐阅读
  • 本文介绍了在Mac上搭建php环境后无法使用localhost连接mysql的问题,并通过将localhost替换为127.0.0.1或本机IP解决了该问题。文章解释了localhost和127.0.0.1的区别,指出了使用socket方式连接导致连接失败的原因。此外,还提供了相关链接供读者深入了解。 ... [详细]
  • Nginx使用(server参数配置)
    本文介绍了Nginx的使用,重点讲解了server参数配置,包括端口号、主机名、根目录等内容。同时,还介绍了Nginx的反向代理功能。 ... [详细]
  • Nginx使用AWStats日志分析的步骤及注意事项
    本文介绍了在Centos7操作系统上使用Nginx和AWStats进行日志分析的步骤和注意事项。通过AWStats可以统计网站的访问量、IP地址、操作系统、浏览器等信息,并提供精确到每月、每日、每小时的数据。在部署AWStats之前需要确认服务器上已经安装了Perl环境,并进行DNS解析。 ... [详细]
  • Skywalking系列博客1安装单机版 Skywalking的快速安装方法
    本文介绍了如何快速安装单机版的Skywalking,包括下载、环境需求和端口检查等步骤。同时提供了百度盘下载地址和查询端口是否被占用的命令。 ... [详细]
  • Spring源码解密之默认标签的解析方式分析
    本文分析了Spring源码解密中默认标签的解析方式。通过对命名空间的判断,区分默认命名空间和自定义命名空间,并采用不同的解析方式。其中,bean标签的解析最为复杂和重要。 ... [详细]
  • VScode格式化文档换行或不换行的设置方法
    本文介绍了在VScode中设置格式化文档换行或不换行的方法,包括使用插件和修改settings.json文件的内容。详细步骤为:找到settings.json文件,将其中的代码替换为指定的代码。 ... [详细]
  • 本文介绍了在rhel5.5操作系统下搭建网关+LAMP+postfix+dhcp的步骤和配置方法。通过配置dhcp自动分配ip、实现外网访问公司网站、内网收发邮件、内网上网以及SNAT转换等功能。详细介绍了安装dhcp和配置相关文件的步骤,并提供了相关的命令和配置示例。 ... [详细]
  • 搭建Windows Server 2012 R2 IIS8.5+PHP(FastCGI)+MySQL环境的详细步骤
    本文详细介绍了搭建Windows Server 2012 R2 IIS8.5+PHP(FastCGI)+MySQL环境的步骤,包括环境说明、相关软件下载的地址以及所需的插件下载地址。 ... [详细]
  • 本文介绍了数据库的存储结构及其重要性,强调了关系数据库范例中将逻辑存储与物理存储分开的必要性。通过逻辑结构和物理结构的分离,可以实现对物理存储的重新组织和数据库的迁移,而应用程序不会察觉到任何更改。文章还展示了Oracle数据库的逻辑结构和物理结构,并介绍了表空间的概念和作用。 ... [详细]
  • 本文介绍了Java工具类库Hutool,该工具包封装了对文件、流、加密解密、转码、正则、线程、XML等JDK方法的封装,并提供了各种Util工具类。同时,还介绍了Hutool的组件,包括动态代理、布隆过滤、缓存、定时任务等功能。该工具包可以简化Java代码,提高开发效率。 ... [详细]
  • Metasploit攻击渗透实践
    本文介绍了Metasploit攻击渗透实践的内容和要求,包括主动攻击、针对浏览器和客户端的攻击,以及成功应用辅助模块的实践过程。其中涉及使用Hydra在不知道密码的情况下攻击metsploit2靶机获取密码,以及攻击浏览器中的tomcat服务的具体步骤。同时还讲解了爆破密码的方法和设置攻击目标主机的相关参数。 ... [详细]
  • 本文介绍了Web学习历程记录中关于Tomcat的基本概念和配置。首先解释了Web静态Web资源和动态Web资源的概念,以及C/S架构和B/S架构的区别。然后介绍了常见的Web服务器,包括Weblogic、WebSphere和Tomcat。接着详细讲解了Tomcat的虚拟主机、web应用和虚拟路径映射的概念和配置过程。最后简要介绍了http协议的作用。本文内容详实,适合初学者了解Tomcat的基础知识。 ... [详细]
  • 本文介绍了作者在开发过程中遇到的问题,即播放框架内容安全策略设置不起作用的错误。作者通过使用编译时依赖注入的方式解决了这个问题,并分享了解决方案。文章详细描述了问题的出现情况、错误输出内容以及解决方案的具体步骤。如果你也遇到了类似的问题,本文可能对你有一定的参考价值。 ... [详细]
  • HDFS2.x新特性
    一、集群间数据拷贝scp实现两个远程主机之间的文件复制scp-rhello.txtroothadoop103:useratguiguhello.txt推pushscp-rr ... [详细]
  • 本文介绍了在Windows环境下如何配置php+apache环境,包括下载php7和apache2.4、安装vc2015运行时环境、启动php7和apache2.4等步骤。希望对需要搭建php7环境的读者有一定的参考价值。摘要长度为169字。 ... [详细]
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社区 版权所有