The web server software Nginx can be installed on Ubuntu in just a few steps. Learn how in­stall­a­tion works and what the server re­quire­ments are.

What are the re­quire­ments of a Nginx web server?

For Nginx you need a server running Linux as the operating system. Ubuntu has proven to be a simple and stable dis­tri­bu­tion. What capacity your Ubuntu server needs depends on your project. Even a small hardware con­fig­ur­a­tion can be enough for a simple website. Nginx is known to save resources without sac­ri­fi­cing per­form­ance.

To start with we recommend:

  • 100 GB storage
  • 6 GB RAM
  • 1 CPU core

When you buy a Cloud Server FLEX package from IONOS, you can configure the hardware as you please. Once your re­quire­ments increase, simply adjust your con­fig­ur­a­tion.

Tip

Sometimes a cloud server isn’t the right choice for your project. With IONOS, you can also get af­ford­able dedicated server hosting, where only you have access to the hardware, and a vServer (VPS) with full vir­tu­al­iz­a­tion.

For others to find your web server online, you’ll need a domain too.

Domain Checker

A step-by-step guide for in­stalling Nginx on Ubuntu 20.04

You can install and configure Nginx on Ubuntu in just a few steps.

Step 1: Download and install software

Before in­stalling Nginx, first update the package man­age­ment of your system:

sudo apt update
sudo apt upgrade
bash

Install Nginx on your system:

sudo apt install nginx
bash

Now confirm the in­stall­a­tion process.

Step 2: Release port

In order to access your web server ex­tern­ally, you’ll need to configure your firewall. Within Ubuntu, the un­com­plic­ated firewall (ufw) program is re­spons­ible for this. For the most re­strict­ive setting possible, choose the following command:

sudo ufw allow 'Nginx HTTP'
bash

This will open port 80. You may have to repeat this in the host settings. In the IONOS Cloud Panel, you can do this via the firewall.

Image: IONOS Cloud Panel: Firewall settings with Port 80 shared
Enable port 80 in the server settings so that visitors can access your web server.

Step 3: Test, start and stop server

Check if in­stall­a­tion of the web server was suc­cess­ful. To do this, enter the following command into terminal:

systemctl status nginx
bash

In the output, you should see that the status of the server is active. Ad­di­tion­ally, you can call the server in the browser. To do this, enter the IP address of the server in the address bar of the browser.

Image: Welcome message of a Nginx web server in the browser
As long as everything worked, you’ll see the Nginx greeting.

You can also start the server manually:

sudo nginx
bash

Besides this command, there are others you can use to control your Nginx web server:

  • stop: Stops the running web server im­me­di­ately
  • quit: Stops the running web server after processes have been executed
  • reload: Reloads the con­fig­ur­a­tion file

The commands can be for­mu­lated using the following pattern:

sudo nginx stop
bash

Step 4: Create test page

Nginx has auto­mat­ic­ally generated a welcome message website under Ubuntu 20.04. You can find the HTML document for this via /var/www/html/. You can now create more HTML documents in this folder and build your own website. However, it’s better to leave the folder untouched and build a new folder for your own domain. To do this, execute the following command:

sudo mkdir -p /var/www/example.com/html
bash

In this example, we use the domain name example.com. Replace all instances with your own domain name and assign the rights:

sudo chown -R $USER:$USER /var/www/example.com/html
sudo chmod -R 755 /var/www/example.com
bash

In the new folder, create your first HTML document – the start page of your project:

sudo nano /var/www/example.com/html/index.html
bash

You can design the page as you see fit. Here’s a simple example that you can fill with your own content:

<html>
    <head>
        <title>Example</title>
    </head>
    <body>
        <h1>Test</h1>
        <p>Welcome to your first website<p>
    </body>
</html>
bash

Save and close the document.

The web server will display the default greeting, so, you need to tell Nginx that the new content should be invoked. To do this, create a new con­fig­ur­a­tion file in the Nginx folder:

sudo nano /etc/nginx/sites-available/example.com
bash

Insert a server block into this file:

server {
    listen 80;
    listen [::]:80;
    root /var/www/example.com/html;
    index index.html index.htm index.nginx-debian.html;
    server_name example.com www.example.com;
    location / {
        try_files $uri $uri/ =404;
    }
}
bash

Be sure to specify the correct port here. If you’ve followed our in­struc­tions, then you’ll have enabled port 80. Save and close the file.

You’ve just created a con­fig­ur­a­tion file in the sites-available folder. Now, you need to create a shortcut in the sites-enabled folder. This folder is used by Nginx at startup to determine which site to serve.

sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
bash

Relaunch the server:

sudo systemctl restart nginx
bash

If you open your domain in the browser, your new website should be displayed.

Go to Main Menu