How to Restart or Reload Nginx Server Service on Linux



Nginx is one of the most popular reverse proxy server used in the tech industry.

If you have hosted an nginx server on a Linux and you want to restart it, you can make use of the service management command like systemctl. But first let's try to understand the difference between restart and reload commands,


Nginx Reload vs Restart

    Restart:

      This will completely restart the Nginx service and will temporary interruption all the existing connections.

    Reload:

      If you have made changes to the configurations of your Nginx server - nginx.conf, then you can make use of the reload command as this will not completely restart the running service and will have minimal impact on the running instance. You can call it a graceful or soft reload.


Important tip:

Before you can either restart or reload the command, it's always a good practice to run a configuration test to make sure that there are no syntax errors in the configuration files. You can call it a hard restart.

# sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Reload Nginx nginx.conf Configuration using systemctl

    Note: By making use of the reload command, the Nginx server will reload the configurations and the active connections will not get impacted.

    sudo systemctl reload nginx

Restart Nginx Service using systemctl

    Note: By making use of the restart command, the Nginx server will get restarted and all active connections will be closed.

    sudo systemctl restart nginx
How to restart or reload nginx service


Send Reload Signal: nginx -s reload

    Instead of using systemctl reload nginx for a full reload, we can make use of the nginx command with a -s flag to send a specific signal to the Nginx process.

    By doing so, you tell the Nginx process to re-read its configuration and apply the changes while keeping existing connections intact.

    nginx -s reload
-

Facing issues? Have Questions? Post them here! I am happy to answer!


Author: Rakesh
Author Info:

Rakesh is a seasoned developer with over 10 years of experience in web and app development, and a deep knowledge of operating systems. Author of insightful How-To articles for Code2care.

Follow him on: X

Copyright © Code2care 2023 | Privacy Policy | About Us | Contact Us | Sitemap