"personal records, there must be a misunderstanding and understanding of the place, small white always has a growing process, I hope you have a lot of advice." "
* Book Access above: CentOS 7 installation Nginx-1.9.2
*nginx after installation, open, close the operation is really long, so ...
First, create a new script:
$ vi/etc/init.d/nginx
Enter the following (this script is a lot of online, copy directly):
#!/bin/sh## nginx-this script starts and stops the Nginx daemin## chkconfig:-About $ Description:nginx is an HTTP ( s) server, HTTP (s) reverse # Proxy and imap/pop3 proxy server# processname:nginx# config:/etc/nginx/n ginx.conf# pidfile:/run/nginx/nginx.pid# Source function Library. /etc/rc.d/init.d/functions# Source Networking configuration: /etc/sysconfig/network# Check that networking are up. ["$NETWORKING" = "no"] && exit 0nginx= "/usr/sbin/nginx" prog=$ (basename $nginx) nginx_conf_file= "/etc/nginx/ Nginx.conf "Lockfile=/var/lock/nginx.lockstart () {[x $nginx] | | Exit 5 [-F $NGINX _conf_file] | | Exit 6 echo -N $ "Starting $prog:" Daemon $nginx-C $NGINX _conf_file retval=$? echo [$retval-eq 0] && touch $lockfile return $retval}stop () {echo-n $ "stopping $prog:" Killproc $prog-quit retval=$? echo [$retval-eq 0] && rm-f $lockfile return $retval}restart () {configtest | | returN $? Stop Start}reload () {configtest | | return $? Echo-n $ "Reloading $prog:" Killproc $nginx-hup retval=$? Echo}force_reload () {restart}configtest () {$nginx-T-C $NGINX _conf_file}rh_status () {status $prog}rh_status_q () {rh_status >/dev/null 2>&1}case "$" in start) Rh_status_q && exit 0 $;; Stop) rh_status_q | | Exit 0 $;; Restart|configtest) \ n; Reload) Rh_status_q | | Exit 7 $;; Force-reload) force_reload;; status) Rh_status;; Condrestart|try-restart) rh_status_q | | Exit 0;; *) echo $ "Usage: $ start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" exit 2esac
Note the configuration of several places, which are those that were set at compile time in Nginx:
# config:/etc/nginx/nginx.conf
# Pidfile:/run/nginx/nginx.pid
nginx= "/usr/sbin/nginx"
nginx_conf_file= "/etc/nginx/nginx.conf"
Lockfile=/var/lock/nginx.lock
Second, add to the service
$ chmod a+x/etc/init.d/nginx$ chkconfig--add nginx$ chkconfig--list nginxnginx 0: Off 1: Off 2: Off 3: Off 4: off 5: off 6: Off
The above is actually a link created under the/etc/rc.d/rc5.d/directory. As follows:
$ cd/etc/rc.d/rc5.d/$ ll |grep nginxlrwxrwxrwx. 1 root root 15 June 16:14 K15nginx. /init.d/nginx
Third, the use
$ service Nginx start $ service nginx stop $ service nginx restart $ service nginx Reload $/etc/init.d/ng Inx start $/etc/init.d/nginx Stop $/etc/init.d/nginx Restart $/etc/init.d/nginx Reload
This is a much simpler operation.Iv. questions:
If you have the following error, go to see if the directory is in the file, if it exists, and the script is correct, then consider the file is not the right format, useful tools on the Web, such as: Doc2unix.
env:/etc/init.d/nginx: No file or directory
My practice is to directly copy the following:
$ rm/etc/init.d/nginx$ Vi/etc/init.d/nginx
Then copy the contents, save them,
$ chmod A+x/etc/init.d/nginx
Remember to modify permissions.
CentOS 7 Nginx Control script