Linux Restart Nginx WebServer Command

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

Tutorial details
Difficulty Easy (rss)
Root privileges Yes
Requirements Linux and Nginx
Time 1m
Nginx is a free and open source web server that runs on Linux and Unix-like systems. This page explains various Linux commands to restart the Nginx web server running on Linux operating systems.

Linux Restart Nginx Webserver

To restart the nginx web server use any one of the following command as a root user as per your Linux distro. Open a terminal or login to the remote server using ssh. For instance:
ssh vivek@server1.cyberciti.biz
sudo systemctl nginx [command]

Debian/Ubuntu/RHEL/CentOS Linux

Linux restart Nginx webserver, run:
# /etc/init.d/nginx restart
OR
# /etc/init.d/nginx reload
One can use the service command for sysv init based systems:
# service nginx restart
OR
# service nginx reload
If you are using systemd based Linux distro:
$ sudo systemctl restart nginx
OR
$ sudo systemctl reload nginx
To view status:
# service nginx status
OR
$ sudo systemctl status nginx
Sample outputs:

Fig.01: Restarting or reloading Nginx server

Using nginx command

Nginx has in built option to send signal to a master process. This should work with any Linux distributions or Unix-like operating systems. The syntax is as follows:
nginx - s signal

Reload Nginx Webserver

# nginx -s reload
OR
# /path/to/full/nginx -s reload

Stop Nginx Webserver

# nginx -s stop
OR
# /path/to/full/nginx -s stop

Exit or Quit Nginx Webserver

# nginx -s quit
OR
# /path/to/full/nginx -s quit

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

How to Start, Stop, or Restart Nginx Server

Here is the summary of all commands that you can pass either to the systemctl command OR service command

Option Description Examples
start Start the Nginx web server sudo systemctl start nginx
sudo service nginx start
stop Stop the Nginx on Linux sudo systemctl stop nginx
sudo service nginx stop
restart Stops and then starts the Nginx web server service sudo systemctl restart nginx
sudo service nginx restart
reload Gracefully restarts the Nginx service after config changes sudo systemctl reload nginx
sudo service nginx reload
status Get the service or server status in Linux sudo systemctl status nginx
sudo service nginx status

How to check nginx server config errors

You need to pass the -t to the nginx command to test configuration and exit. For example:
nginx -t
Pass the -T to test configuration, dump it on screen and exit, run:
nginx -T

How to send signal to a Nginx

The syntax is as follows for Linux and Unix users:
nginx -s signal
Signal can be stop, quit, reopen and reload. For instance, we can send reload signal as follows as the root user:
# nginx -t
# nginx -s reload

See nginx docs here for more info.

Conclusion

In this tutorial, you learned how to start, stop, and restart the Nginx web server on Linux systems using command line options.


🐧 Please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
3 comments… add one
  • Willie Jackson Aug 27, 2010 @ 6:55

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

    • ITN John Apr 24, 2013 @ 20:17

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

  • Minecraft Dec 2, 2014 @ 4:41

    Thanks for you,
    I always use “service nginx restart” after config nginx

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Problem posting comment? Email me @ webmaster@cyberciti.biz