How to Install Nginx on Ubuntu 20.04 | 18.04

Nginx which is a high-performance HTTP and reverse proxy server can be installed and managed easily in Ubuntu.
This post shows you how to do that.

This brief tutorial shows students and new users how to install Nginx HTTP server on Ubuntu 20.04 | 18.04.

Nginx, pronounced “engine x” is a free, opensource, cross-platform, high-performance HTTP and reverse proxy that can be used to mange high traffic websites.

Whether you want to run a personal website or company portal, Nginx is a powerful webserver that can serve all your users.

Installing Nginx on Ubuntu is pretty simple and straightforward. In fact, Nginx packages are available in Ubuntu repositories.

All one has to do is run the apt get command to install it.

To get started with installing Nginx, follow the steps below:

Step 1: Install Nginx

As we mentioned above, installing Nginx is simple and straightforward. Because it stable packages come with Ubuntu, simply run the commands below to install.

sudo apt update
sudo apt install nginx

After installing the package above, you can check Nginx status by running the commands below:

sudo systemctl status nginx

That should display similar lines as shown below:

 nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabl>
Active: active (running) since Fri 2020-05-01 22:44:46 CDT; 10s ago
Docs: man:nginx(8)
Main PID: 3361 (nginx)
Tasks: 2 (limit: 4657)
Memory: 3.2M
CGroup: /system.slice/nginx.service
├─3361 nginx: master process /usr/sbin/nginx -g daemon on; master_proces>
└─3362 nginx: worker process

Step 2: Managing Nginx

When you install Nginx, it might be good to how to manage the server’s services. To learn how to stop,start, restart Nginx services, the commands below will be helpful.

To stop Nginx services, run the commands below:

sudo systemctl stop nginx

To start it, run the commands below:

sudo systemctl start nginx

To restart it, run the commands below:

sudo systemctl restart nginx

Reload allows you to apply new configuration changes without restarting the services.

sudo systemctl reload nginx

If Ubuntu server is protected by a firewall you’ll need to open HTTP 80 and HTTP 443 ports to allow communication to the Nginx.

Assuming you’re using Ubuntu default firewall, run the commands below:

sudo ufw allow 'Nginx Full'

To validate that Nginx is working, open your web browser and browse to the server IP address or hostname.


nginx default home page test

If you see a similar page below, then Nginx is working as expected.

Step 3: Important Locations

By default, these important locations are automatically created on Ubuntu servers. Below are some details of each location.

All Nginx configuration files are located in: /etc/nginx directory.

Nginx main configuration file is at /etc/nginx.

Each website will be hosted as a server block file. All server block files are stored in /etc/nginx/sites-available.

Server block files in the location above will not be enabled unless they’re linked in this directory: /etc/nginx/sites-enabled.

To simplify Nginx management, you should create a separate configuration file for each domain. You can have as many server block files as you need.

Configuration snippets that can be included in Nginx site configuration file are created in /etc/nginx/snippets.

To activate a server block, run the commands below:

sudo ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/

To disable, run the commands below

sudo rm /etc/nginx/sites-enabled/

That should be a good started point.

More configurations and files are available in the main configuration directory. Look them up, read about them and use them.


This post showed you how to install Nginx HTTP server on Ubuntu 20.04 | 18.04. If you find any error above, please use the comment form below to report it.


You may also like the post below:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.