How to Install Nginx on Ubuntu 20.04 Server

Summary: Step-by-step guide to install and run Nginx web server on Ubuntu.


Nginx (pronounced “engine-x”) is a high-performance, open-source web server that’s widely used to power websites, reverse proxies, and load balancers. If you are running Ubuntu 20.04 and want a modern, stable web server, Nginx is a fantastic choice. This guide will walk you through each step of the installation process, from updating your system to configuring Nginx for your application.


Table of Contents

  1. Prerequisites
  2. Step 1: Update the System
  3. Step 2: Install Nginx
  4. Step 3: Adjusting the Firewall (UFW)
  5. Step 4: Checking Nginx Status
  6. Step 5: Testing the Web Server
  7. Step 6: Managing the Nginx Service
  8. Conclusion

Prerequisites

  • A server running Ubuntu 20.04 (Focal Fossa)
  • A user account with sudo privileges
  • Internet connection

Step 1: Update the System

Before installing any software, update your package list to make sure you have access to the latest versions:

sudo apt update
sudo apt upgrade

This ensures your server is up-to-date and secure.


Step 2: Install Nginx

Nginx is available in Ubuntu’s default repositories. To install it, simply run:

sudo apt install nginx
  • When prompted, type Y then Enter to confirm the installation.

Step 3: Adjusting the Firewall (UFW)

Ubuntu 20.04 usually comes with UFW (Uncomplicated Firewall). To allow HTTP and HTTPS traffic through the firewall, run:

sudo ufw allow 'Nginx HTTP'

or, to enable HTTPS as well for future SSL setup:

sudo ufw allow 'Nginx Full'

Enable the firewall if it’s not already enabled:

sudo ufw enable

Check firewall status with:

sudo ufw status

Your server is now ready to serve web traffic!


Step 4: Checking Nginx Status

Nginx starts automatically after installation. To verify it’s running:

systemctl status nginx

The output should indicate it is active (running). If not, start the service:

sudo systemctl start nginx

You may also want to enable Nginx on system boot:

sudo systemctl enable nginx

Step 5: Testing the Web Server

With Nginx running, it serves a default web page. To test:

  1. Locate your server’s public IP address:

    ip a
    

    or

    curl -4 ifconfig.me
    
  2. Open a web browser and navigate to:

    http://your_server_ip
    

    You should see the Nginx default welcome page:

    Welcome to nginx!

If you see this, Nginx is working properly.


Step 6: Managing the Nginx Service

Here are some useful commands to manage Nginx:

  • Stop Nginx:
    sudo systemctl stop nginx
    
  • Start Nginx:
    sudo systemctl start nginx
    
  • Restart Nginx:
    sudo systemctl restart nginx
    
  • Reload Nginx (for config changes):
    sudo systemctl reload nginx
    
  • Enable Nginx at boot:
    sudo systemctl enable nginx
    
  • Disable Nginx at boot:
    sudo systemctl disable nginx
    

Conclusion

You’ve successfully installed and started the Nginx web server on Ubuntu 20.04! From here, you can host websites, configure reverse proxies, or serve web apps. Be sure to explore the Nginx documentation for advanced configuration, security, and performance optimization tips.

If you plan to use SSL/TLS, consider setting up HTTPS with Let’s Encrypt in your next steps.

Happy hosting!