Nginx 开机启动

首先,在linux系统的/etc/init.d/目录下创建nginx文件,使用如下命令:
vi /etc/init.d/nginx
在脚本中添加如下命令:

#!/bin/bash

# nginx Startup script for the Nginx HTTP Server

# it is v.0.0.2 version.

# chkconfig: - 85 15

# description: Nginx is a high-performance web and proxy server.

#   It has a lot of features, but it‘s not for everyone.

# processname: nginx

# pidfile: /var/run/nginx.pid

# config: /usr/local/nginx/conf/nginx.conf

nginxd=/usr/local/nginx/sbin/nginx

nginx_config=/usr/local/nginx/conf/nginx.conf

nginx_pid=/var/run/nginx.pid

RETVAL=0

prog="nginx"

# Source function library.

. /etc/rc.d/init.d/functions

# Source networking configuration.

. /etc/sysconfig/network

# Check that networking is up.

[ ${NETWORKING} = "no" ] && exit 0

[ -x $nginxd ] || exit 0

# Start nginx daemons functions.

start() {

if [ -e $nginx_pid ];then

echo "nginx already running...."

exit 1

fi

echo -n $"Starting $prog: "

daemon $nginxd -c ${nginx_config}

RETVAL=$?

echo

[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx

return $RETVAL

}

# Stop nginx daemons functions.

stop() {

echo -n $"Stopping $prog: "

killproc $nginxd

RETVAL=$?

echo

[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid

}

# reload nginx service functions.

reload() {

echo -n $"Reloading $prog: "

#kill -HUP `cat ${nginx_pid}`

killproc $nginxd -HUP

RETVAL=$?

echo

}

# See how we were called.

case "$1" in

start)

start

;;

stop)

stop

;;

reload)

reload

;;

restart)

stop

start

;;

status)

status $prog

RETVAL=$?

;;

*)

echo $"Usage: $prog {start|stop|restart|reload|status|help}"

exit 1

esac

exit $RETVAL

注意红色加粗部分,需要将路径改为自己机器的相应路径。

接着,设置文件的访问权限:

chmod a+x /etc/init.d/nginx

(a+x参数表示 ==> all user can execute  所有用户可执行)

最后将ngix加入到rc.local文件中,这样开机的时候nginx就默认启动了

vi /etc/rc.local

添加

/etc/init.d/nginx start  

保存并退出

下次重启就会生效,实现nginx的自启动

时间: 2024-11-05 01:02:05

Nginx 开机启动的相关文章

设置nginx开机启动

制作nginx开机启动脚本: vi /etc/init.d/nginx -------------------------------以下是脚本内容-------------------------------------- #! /bin/sh# Default-Start: 2 3 4 5# Default-Stop: 0 1 6# Short-Description: starts the nginx web server PATH=$PATH:/usr/local/nginxDESC="

nginx开机启动

nginx开机启动使用的是编写shell脚本的方式来处理,如下: [[email protected] ~]# vi /etc/init.d/nginx #!/bin/bash # nginx Startup script for the Nginx HTTP Server # it is v.1.11.3 version. # chkconfig: - 85 15 # description: Nginx is a high-performance web and proxy server.

centos6.5 nginx开机启动

/etc/init.d/下添加nginxd文件,内容如下: #!/bin/bash # #chkconfig: - 85 15 #description: Nginx is a World Wide Web server. #processname: nginx nginx=/usr/local/nginx/nginx conf=/usr/local/nginx/nginx.conf case $1 in start) echo -n "Starting Nginx" $nginx -

Centos7 Nginx 开机启动

Centos 系统服务脚本目录: 用户(user) 用户登录后才能运行的程序,存在用户(user) /usr/lib/systemd/ 系统(system) 如需要开机没有登陆情况下就能运行的程序,存在系统服务(system)里 /lib/systemd/system/ 服务以.service结尾. vim /lib/systemd/system/nginx.service [Unit] Description=nginx After=network.target [Service] Type=

[转]centos7.2 下 nginx 开机启动

1.在系统服务目录里创建nginx.service文件 vi /lib/systemd/system/nginx.service 内容如下 [Unit] Description=nginx After=network.target [Service] Type=forking ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/usr/local/nginx/sbin/nginx -s reload ExecStop=/usr/local/ngin

ubuntu nginx 开机启动

这里需要特别说明的是,Ubuntu系统下没有RedHat系统下的chkconfig命令.但Ubuntu有一个类似的命令: sysv-rc-conf. 通过apt-get命令完成sysv-rc-conf软件的安装. 背景 Linux系统的运行级别有7个,分别对应的: 0: 关机 1: 单用户(维护) 2~5: 多用户 6: 重启 可以通过runlevel命令来查看当前系统的运行等级: wds@wds-VirtualBox:~$ runlevel N 2 其中第一个表示上一次的运行等级,N表示没有上

nginx开机启动脚本

#!/bin/sh#nginx start stop restart reload#by zkg 2019-08-13#chkconfig: 2345 32 62#description: nginx is http server #system functions[ -f /etc/init.d/functions ] && . /etc/init.d/functions #Define variablesPIDFILE=/data/nginx/logs/nginx.pidSRC_PWD

Linux配置Nginx,MySql,php-fpm开机启动的方法

一. Nginx 开机启动 NGINX SHELL脚本   放到/etc/init.d/下取名nginx 下面代码里根据你原始安装路径去更改 nginx="/usr/localinx/sbininx" NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf" [plain] view plain copy #!/bin/sh # # nginx - this script starts and stops the ngin

centos7 nginx 加入开机启动

设置nginx开机启动 vi /etc/rc.d/init.d/nginx  #编辑启动文件添加下面内容 ############################################################ #!/bin/sh # # nginx - this script starts and stops the nginx daemon # # chkconfig: - 85 15 # description: Nginx is an HTTP(S) server, HT