Nginx manual start
Stop operation
The stop operation is performed by sending a signal to the nginx process (for more information about the signal, see The linux chapter).
Step 1: query the nginx master process number
Ps-ef | grep nginx
Find the master process in the process List. Its number is the master process number.
Step 2: send signals
Stop Nginx with ease:
Kill-QUIT master process number
Stop Nginx quickly:
Kill-TERM Master process number
Force stop Nginx:
Pkill-9 nginx
In addition, if the pid file storage path is configured in nginx. conf, the file stores the Nginx main process number. If no pid file is specified, the file is placed in the nginx logs directory. With the pid file, we do not need to first query the main process Number of Nginx, but directly send a signal to Nginx. The command is as follows:
Kill-signal type '/usr/nginx/logs/nginx. pid'
Command:/usr/local/nginx/sbin/nginx
If:
[Root @ kangxiaowei ~] #/Usr/local/nginx/sbin/nginx
[Emerg]: bind () to 0.0.0.0: 80 failed (98: Address already in use)
[Emerg]: bind () to 0.0.0.0: 80 failed (98: Address already in use)
[Emerg]: bind () to 0.0.0.0: 80 failed (98: Address already in use)
[Emerg]: bind () to 0.0.0.0: 80 failed (98: Address already in use)
[Emerg]: bind () to 0.0.0.0: 80 failed (98: Address already in use)
[Emerg]: still cocould not bind ()
Run/root/lnmp stop again to disable lnmp.
Nginx boot script
Start nginx automatically at startup,
If you need to start the service, after saving the/etc/init. d/nginx file,
Run the following command:
The code is as follows: |
Copy code |
Chkconfig -- add ningx Chkconfig -- level nginx 2345 on |
Automatic startup script
The code is as follows: |
Copy code |
#! /Bin/sh # Chkconfig: 2345 55 25 # Description: Startup script for nginx webserver on Debian. Place in/etc/init. d and # Run 'UPDATE-rc. d-f nginx defaults', or use the appropriate command on your # Distro. For CentOS/Redhat run: 'chkconfig -- add nginx' ### BEGIN INIT INFO # Provides: nginx # Required-Start: $ all # Required-Stop: $ all # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: starts the nginx web server # Description: starts nginx using start-stop-daemon ### END INIT INFO PATH =/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin DESC = "nginx daemon" NAME = nginx DAEMON =/usr/local/platform/nginx/sbin/$ NAME CONFIGFILE =/usr/local/platform/nginx/conf/$ NAME. conf PIDFILE =/usr/local/platform/nginx/logs/$ NAME. pid SCRIPTNAME =/etc/init. d/$ NAME Set-e [-X "$ DAEMON"] | exit 0 Do_start (){ $ DAEMON-c $ CONFIGFILE | echo-n "nginx already running" } Do_stop (){ Kill-INT 'cat $ pidfile' | echo-n "nginx not running" } Do_reload (){ Kill-HUP 'cat $ pidfile' | echo-n "nginx can't reload" } Case "$1" in Start) Echo-n "Starting $ DESC: $ NAME" Do_start Echo "." ;; Stop) Echo-n "Stopping $ DESC: $ NAME" Do_stop Echo "." ;; Reload | graceful) Echo-n "Reloading $ DESC configuration ..." Do_reload Echo "." ;; Restart) Echo-n "Restarting $ DESC: $ NAME" Do_stop Do_start Echo "." ;; *) Echo "Usage: $ SCRIPTNAME {start | stop | reload | restart}"> & 2 Exit 3 ;; Esac Exit 0 |
The configurations you need to modify include
The code is as follows: |
Copy code |
#! /Bin/sh PATH =/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin NAME = nginx DAEMON =/usr/local/nginx/sbin/$ NAME CONFIGFILE =/usr/local/nginx/conf/$ NAME. conf PIDFILE =/usr/local/nginx/logs/$ NAME. pid |
Save the edited file and run the following command:
The code is as follows: |
Copy code |
1 chmod + x/etc/init. d/nginx |
Now add Nginx to chkconfig and set it to start upon startup.
The code is as follows: |
Copy code |
12 chkconfig -- add nginx chkconfig nginx on |
# Check
The code is as follows: |
Copy code |
1 chkconfig -- list nginx Nginx 0: off 1: off 2: on 3: on 4: on 5: on 6: off |