Home > php教程 > PHP开发 > nginx starts the service automatically when booting

nginx starts the service automatically when booting

高洛峰
Release: 2016-12-01 13:33:12
Original
1397 people have browsed it

Production server:

OS: CentOS 6.8

1. Create a new nginx file in the directory "/etc/init.d" and add the following code.

[root@localhost init.d]# vi nginx

[root@localhost init.d]# cat nginx

#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=/application/nginx/sbin/nginx

nginx_config=/application/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

)

         [ $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

                                                   

restart)

Stop

start

;;

status)

status $prog

                                                                          RETVAL=$?

exit $ RETVAL

2. Set up the startup service, save the /etc/init.d/nginx file, and execute the following command:

[root@localhost init.d]# chmod 755 /etc/init.d/nginx #Give File execution permissions

[root@localhost init.d]# chkconfig --add nginx

[root@localhost init.d]# chkconfig --level 2345 nginx on #Set up startup

3. nginx start, stop, Non-stop service restart

[root@localhost /]# service nginx status

nginx (pid 1621 1619) is running...

[root@localhost /]# service nginx stop

Stop nginx:                                                                                                                                                                                                                            [Confirmed]

[root@localhost /]# service nginx start

Starting nginx:                                                                                                                                                                                                                                                     because
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template