I'm available to deliver your SaaS MVP in a few weeks, full-stack with the new Next.js App Router. Accelerate Your MVP Launch Now.

How to install Nginx on Linux

Learn how to install Nginx on Debian or Ubuntu in 5 steps.

Flavio Silva
Flavio SilvaJuly 16, 2014
Updated on April 6, 2023
How to install Nginx on Linux
Image by fullvector on Freepik

The superfast, open-source Nginx HTTP webserver is becoming very popular nowadays. Fortunately, it's very simple to install and set it up, as we'll see in this tutorial.

If you want to know about how to securely set up a Linux VPS (Ubuntu & Debian) click here to read my article about just that.

Do not type the $ sign you see in the command examples in this article. That's just an indicator that you should run the command that follows it in your command line tool.

Step 1. Updating your Linux distro

It's always a good practice to start with everything up to date, so after connecting to your server via SSH, update your Linux distro:


$ sudo apt-get update
$ sudo apt-get upgrade --show-upgraded

Step 2. Installing Nginx

To install Nginx run the following command:


$ sudo apt install nginx

Step 3. Checking your installation

Now let's make sure it's installed, and which version.


$ sudo nginx -v

You should see something like this:


"nginx version: nginx/1.18.0"

That should be very close to the latest version!

Step 4. Checking the status of Nginx

At any time you want, you can check the status of Nginx, for example, wether it's running.

Let's do that now to see if Nginx is already running. It should be as it's Debian's default behavior, but let's make sure by running the following command:


$ sudo systemctl status nginx

You should see a bunch of useful information, including something like this:


Active: active (running)

That means Nginx is up and running! 😎

If you're setting up a VPS from scratch, you can now try to access its IP on your browser. You should see something like this:


"Welcome to nginx!"

Congrats! Nginx is up and listening to port 80 (HTTP). If your server is restarted, you don't have to worry about Nginx, it'll be initialized automatically!

Step 5. Managing the Nginx process

You'll probably have to manage Nginx using a few commands throughout your sysadmin activities.

For example, every time you change a website configuration file, or even Nginx's configuration file, you need to reload Nginx so it can take those changes into account. To do that, you run the following command:


$ sudo systemctl reload nginx

You'll get an error message if there's an error in any configuration file. Otherwise, you won't get any feedback.

There is also the start, stop and restart commands that you might need at some point:


$ sudo systemctl stop nginx


$ sudo systemctl start nginx


$ sudo systemctl restart nginx

The restart command will stop and start it again.

Updating Nginx

You can update Nginx at any time by running:


$ sudo apt-get update
$ sudo apt-get upgrade nginx

And that's it. You can find more posts related to Nginx and sysadmin in the Related posts section below.

How to set up a website on Linux + Nginx
How to password-protect content on Linux + Nginx
Wildcard HTTPS on Linux + Let's Encrypt + Nginx
What are HTTPS, TLS certificates, and Let's Encrypt?
How to set up a Linux VPS

Nginx
Nginx - Wikipedia

Bibliography

"Virtual Private Server - Wikipedia" Wikipedia , n.d. Web. 06 May 2014 <http://en.wikipedia.org/wiki/Virtual_private_server>

How to install Nginx on Linux by Flavio Silva is licensed under a Creative Commons Attribution 4.0 International License.

Leave a comment using your GitHub account

© 2024 Flavio Silva