Linux: Restart Nginx WebServer

in Categories CentOS, Debian / Ubuntu, Fedora Linux, Linux, Nginx, RedHat and Friends, Suse last updated January 21, 2017

How do I restart nginx web server under Linux or Unix operating systems using command line options?

To restart the nginx web server use any one of the following command as a root user. Open a terminal or login to the remote server using ssh.

Debian/Ubuntu/RHEL/CentOS Linux

Use the following command:
# /etc/init.d/nginx restart
# /etc/init.d/nginx reload
# service nginx restart
# service nginx reload
OR if you are using systemd based Linux distro:
$ sudo systemctl restart nginx
$ sudo systemctl reload nginx
To view status:
# service nginx status
$ sudo systemctl status nginx
Sample outputs:

Fig.01: Restarting or reloading Nginx server
Fig.01: Restarting or reloading Nginx server

However, recommend way is as follows. This should work with any Linux distributions or Unix-like operating systems:
# nginx -s reload
# /path/to/full/nginx -s reload

If nginx compiled and installed from the source code

If nginx binary is installed at /usr/local/nginx/sbin/nginx, enter:
# /usr/local/nginx/sbin/nginx -s reload

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

Share this on (or read 3 comments/add one below):

3 comment

  1. The method used is largely determined by whether NGINX was installed via package manager or compiled from source, correct?

    1. I guess so. If compiled from source use /path/to/nginx -s reload else use service nginx reload or service nginx restart

    Have a question? Post it on our forum!