How to Start, Stop, and Restart Nginx (systemctl & Nginx Commands)

Introduction

Nginx is a powerful web server that is used to serve web content to users. It is a popular choice for web hosting due to its scalability and performance. In order to ensure that your Nginx server is running optimally, it is important to know how to start, stop, and restart it. This tutorial will provide instructions on how to do this using both systemctl and Nginx commands. By following these steps, you will be able to ensure that your Nginx server is running smoothly and efficiently.

How to Start, Stop, and Restart Nginx (systemctl & Nginx Commands)

1. Start Nginx (systemctl):

sudo systemctl start nginx

2. Stop Nginx (systemctl):

sudo systemctl stop nginx

3. Restart Nginx (systemctl):

sudo systemctl restart nginx

4. Start Nginx (Nginx command):

sudo nginx

5. Stop Nginx (Nginx command):

sudo nginx -s stop

6. Restart Nginx (Nginx command):

sudo nginx -s reload
[ad_1]

Introduction

Nginx is a powerful server application that routes network traffic. It’s often used as a reverse proxy server, but can also be configured as a regular web server.

One of the most common operations you will encounter is starting, stopping, and restarting the Nginx web server.

In this tutorial, learn how to start, stop, and restart the Nginx service.

Commands to stop, start, and restart Nginx in linux

Prerequisites

  • A system with Nginx installed and configured
  • Access to a terminal window or command line
  • A user account with sudo or root privileges
  • An existing SSH connection to a remote system (if you’re working remotely)

Start, Stop, and Restart Nginx with systemctl

How to View Status of Your Nginx Server

Nginx runs as a service on your server. That means that it should be actively running in the background, even if you don’t see anything on the screen. You can display the status of the Nginx service by entering the following command in a terminal window:

sudo systemctl status nginx

The system will switch into a status mode, displaying lots of information about the Nginx service.

  • If the service is running (active), you’ll see a green active (running) status in the third line.
  • If Nginx is not running, it will display as inactive in standard white.
  • If something went wrong and Nginx couldn’t load, you’ll see a red status failed, with some information about the failure.
Checking the status of an Nginx webserver in terminal

Press q to reactivate the bash prompt.

SystemD is the default service manager on modern versions of Linux distributions (Ubuntu 20.04/18.04/16.04, CentOS 7/7, and Debian 9/10). The SystemD manager functions through the systemctl command.

The systemctl command is a base Linux command. That means that it can be used for any Linux service.

Stop and Start Nginx

systemctl can be used to start and stop the Nginx service.

To stop Nginx, run the following command:

sudo systemctl stop nginx
Terminal command to stop an Nginx web server

To start Nginx, execute the systemctl command with the start option:

sudo systemctl start nginx
systemctl command to start the Nginx service

How to Restart Nginx

Gracefully Restart Nginx

If you’re refreshing Nginx after changing the configuration, it’s best to gracefully reload the service. That shuts down old processes and restarts new ones with the new configuration.

Use the systemctl Linux command to reload the Nginx service. Run the following command:

sudo systemctl reload nginx

Note: Nginx cannot be reloaded if the the Nginx service is not active.

Force Restart Nginx

For major configuration changes, you can force a full restart of Nginx. This force-closes the whole service and sub-processes, and restarts the whole package.

Enter the following command:

sudo systemctl restart nginx

Restart vs Reload Nginx

The reload command keeps the Nginx server running as it reloads updated configuration files. If Nginx notices a syntax error in any of the configuration files, the reload is aborted and the server keeps running based on old config files. Reloading is safer than restarting Nginx.

The restart command will shut down the server including all related services and power it on again. Restart Nginx only when making significant configuration updates, such as changing ports or interfaces. This command will force shut down all worker processes.

Configure Nginx to Launch on Boot

Use the enable option with the systemctl command to enable Nginx:

sudo systemctl enable nginx

Use the disable option with the systemctl command to disable Nginx:

sudo systemctl disable nginx

Start, Stop, and Reload Nginx with the Nginx Command

Nginx has a set of built-in tools for managing the service that can be accessed using the Nginx command.

Nginx Start

To start Nginx and related processes, enter the following:

sudo /etc/init.d/nginx start

If run successfully, the terminal output will display the following:

Output
[ ok ] Starting nginx (via systemctl): nginx.service.

Nginx Restart

To force close and restart Nginx and related processes:

sudo /etc/init.d/nginx restart
Restart nginx with nginx restart command.

As an alternative, use the nginx -s command:

sudo nginx -s restart

Nginx Stop

To disable or stop the Nginx service, enter the following:

sudo /etc/init.d/nginx stop
Stop the Nginx service with the nginx stop command

Alternatively, use:

sudo nginx -s stop

Nginx Reload

To gracefully stop and restart Nginx and related processes, use the command:

sudo /etc/init.d/nginx reload
Reload Nginx with in-built Nginx reload command.

Alternately, you can use the nginx -s command to pass instructions directly to Nginx:

sudo nginx -s reload

Nginx Quit

Force close the Nginx service by using the quit instruction with the nginx -s command:

sudo nginx -s quit

Conclusion

This article has outlined several methods to start, stop, and restart Nginx on your server. Use these commands for the most common operations when managing an Nginx web server.

[ad_2]

How to Start, Stop, and Restart Nginx (systemctl & Nginx Commands)

Nginx is a popular web server used to host websites and applications. It is important to know how to start, stop, and restart Nginx in order to manage your web server properly. In this article, we will discuss how to start, stop, and restart Nginx using both systemctl and Nginx commands.

Using Systemctl to Start, Stop, and Restart Nginx

The systemctl command is used to manage system services on Linux systems. To start, stop, and restart Nginx using systemctl, use the following commands:

  • To start Nginx: sudo systemctl start nginx
  • To stop Nginx: sudo systemctl stop nginx
  • To restart Nginx: sudo systemctl restart nginx

Using Nginx Commands to Start, Stop, and Restart Nginx

Nginx also provides its own set of commands to manage the web server. To start, stop, and restart Nginx using Nginx commands, use the following commands:

  • To start Nginx: sudo nginx -s start
  • To stop Nginx: sudo nginx -s stop
  • To restart Nginx: sudo nginx -s reload

It is important to note that the Nginx commands will only work if Nginx is installed in the default location. If Nginx is installed in a custom location, you will need to specify the path to the Nginx binary when running the commands.

Conclusion

In this article, we discussed how to start, stop, and restart Nginx using both systemctl and Nginx commands. Knowing how to manage your web server is an important part of running a successful website or application.

Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Jassweb.com/

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

GSTIN is 03EGRPS4248R1ZD.

Contact
Jassweb, Rai Chak, Punjab, India. 143518
Item added to cart.
0 items - 0.00