Starting

Stopping

There are two ways to stop Nginx - immediately using the TERM signal, or gracefully using the QUIT signal:

/usr/local/nginx/sbin $ ./nginx -s stop

/usr/local/nginx/sbin $ ./nginx -s quit

Reloading Configuration

/usr/local/nginx/sbin $ ./nginx -s reload

All of the above commands will verify the configuration file each time they are run, even when you’re trying to stop Nginx. When you’re unable to stop Nginx using ./nginx -s stop, you may use kill or killall:

$ killall nginx

Testing Your Configuration

Optionally, you can specify a path with -c so that you can test another configuration file:

$ ./nginx -t -c /home/siawyoung/test.conf

Nginx as a system service

Adding Nginx as a system service allows us to:

Control it with standard commands

Have it launch and quit at system startup and shutdown automatically

To add Nginx as a system service, we simply need to include a script in /etc/init.d/ called nginx1. There’re many resources out there which covers Nginx init scripts.

Footnotes

Linux-based operating systems have 7 runlevels which correspond to different system states (0 means the system is shut down, 3 means the system is in multiuser mode, etc). Each state is associated with a folder in /etc called rc*.d. Each folder contains symbolic links to scripts located in init.d. A daemon called init is responsible for running the scripts associated with each state . Thus, what update-rc.d -f nginx defaults does is it creates a symbolic link to the nginx script within the rc*.d that is associated with the OS’s default state upon startup (for Ubuntu its 3).