Nginx

Start, Stop, and Restart Nginx Web Server on Linux

Start, Stop, and Restart Nginx Web Server on Linux
NGINX is an open-source web server with features for load balancing, caching, and functioning as a reverse proxy.

Igor Sysoev created it to overcome the limits of scaling and concurrency existing within regular web servers, offering an event-based, asynchronous architecture that enhances NGINX's performance and stability as a web server.

As is the case with managing all servers, you'll find yourself needing to start, stop, and restart the NGINX web server for various reasons.

This guide discusses how to use various methods to manage the NGINX service running on a Linux system.

NOTE: If you are running NGINX on a remote server, you will need to have an SSH connection. Ensure you also have sudo or root access to your system.

How to Manage the NGINX Service With The Systemd Service Manager

One way to manage NGINX service is by using the systemd service manager, commonly accessible using the systemctl command. This method will only work if the system where NGINX is installed uses systemd as its service manager.

How to View the NGINX web server status

In most cases, NGINX is installed as a service and runs in the background. Although NGINX runs in the background, there are ways to view the service status using the systemctl utility.

To view how the service is running, open the terminal window, and enter the command:

sudo systemctl status nginx

The command above will display information about the NGINX service. The command will display either of the following scenarios.

NOTE: Press Q to quit from status mode to shell.

How To Use systemd to Start and Stop the Nginx Service

Systemd is a universal utility that manages services in most Linux distribution. If NGINX is configured to run as a service, we can use the systemd to start and stop it.

To start the Nginx service, use the command:

sudo systemctl start nginx

To stop Nginx, use the command:

sudo systemctl stop nginx

How to Use systemd to restart the NGINX Service

You can also use the systemd to restart the NGINX service. Restarting a service shuts down all the running processes and restarts them afresh. Restarting a service is very useful when applying configuration changes to the server, eliminating the need to reboot the entire system.

There are two ways to restart a service:

How to Reload the Nginx Service (Graceful restart)

To restart the NGINX service gracefully using systemd, use the command:

sudo systemctl reload nginx

The above command requires the service to be running.

How to Force Restart Nginx Service

If you are performing critical changes to the NGINX server, you should reboot the service. Restarting force-closes all running processes, reinitializes them, and applies new changes. This is very useful when performing updates, changing ports, network interfaces, etc.

You can use the command:

sudo systemctl restart nginx

How to Manage The NGINX Service With Nginx Commands

NGINX has a set of built-in tools that are accessible using the Nginx command. We can use these commands to interact with the service manually.

How to use Nginx commands to start NGINX

You can start the NGINX service using the command

sudo /etc/init.d/nginx start

This command will display the output indicating that the service is starting-as shown in the image below:

How to stop the NGINX web server using Nginx commands

To stop the Nginx service and all related processes, you can use the command:

sudo /etc/init.d/nginx stop

You will get an output such as the one shown below:

How to force-close and restart the NGINX web server using a command

You can also force close and restart all nginx processes using the command:

sudo /etc/init.d/nginx restart or sudo nginx -s reopen

How to reload the NGINX web server using a command

To reboot the nginx service and its processes gracefully, you use the command:

sudo /etc/init.d/nginx reload or sudo nginx -s reload

How to force-terminate the NGINX server a using command

If you want to force-close all Nginx services without rebooting, use the command

nginx -s quit

Conclusion

In this article, we have discussed various methods you can use to interact with the NGINX service. Using what you've learned, you can manage the Nginx web server and troubleshoot server related problems.

Cele mai bune emulatoare pentru console de jocuri pentru Linux
Acest articol va enumera programele populare de emulare a consolei de jocuri disponibile pentru Linux. Emularea este un strat de compatibilitate softw...
Best Linux Distros for Gaming in 2021
The Linux operating system has come a long way from its original, simple, server-based look. This OS has immensely improved in recent years and has no...
Cum să capturați și să transmiteți în flux sesiunea de jocuri pe Linux
În trecut, jocurile erau considerate doar un hobby, dar cu timpul industria jocurilor a cunoscut o creștere imensă în ceea ce privește tehnologia și n...