To gracefully restart the Nginx web server after making changes to a configuration file, follow these steps:
Open a terminal and log in as the root
user or use sudo
to execute the commands.
Check the syntax of the Nginx configuration file by running the following command:
nginx -t
This will check the syntax of the configuration file and display any errors or warnings.
nginx -s reload
This will gracefully reload the configuration file, allowing existing connections to complete while new connections will be handled with the new configuration.
systemctl status nginx
This will display the status of the Nginx service. The output should show that the service is active and running.
Note: If you made changes to the Nginx configuration file that caused the server to fail to start, you may need to use the
nginx -s stop
command to stop the Nginx server and then start it again using thesystemctl start nginx
command.