Install and set up Nginx on Ubuntu server

Learn how to install and configure Nginx on your Ubuntu server.

1 min
NginxServerUbuntu

Update System Packages

First, let’s update the database of available packages versions.

bash logo
sudo apt update

Install Nginx

Install nginx with the following command:

bash logo
sudo apt install nginx -y

Check The installation

bash logo
nginx -v

you should see the version of nginx installed, for example:

text logo
nginx version: nginx/1.24.0 (Ubuntu)

Adjust Firewall Settings

Depending on your previous firewall configuration, you may need to allow nginx in the firewall, nginx already registers it self as a service with ufw on installation, making it easy for us to allow it through the firewall.

Allow Nginx Full (recommended)
sudo ufw allow 'Nginx Full'
Allow Nginx HTTP only
sudo ufw allow 'Nginx HTTP'
Allow Nginx HTTPS only
sudo ufw allow 'Nginx HTTPS'

You can check the status of the firewall with:

bash logo
sudo ufw status

In the output you should see the nginx profile you allowed, for example:

Output text logo
Status: active
To                         Action      From
--                         ------      ----
Nginx Full                 ALLOW       Anywhere

Check Nginx Service Status

Nginx should be running after the installation, you can check it’s status at any time with:

bash logo
sudo systemctl status nginx

You should see an output similar to this:

Output text logo
● nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; preset: enabled)
     Active: active (running) since Wed 2026-06-24 06:35:18 CEST; 1 week 2 days ago
       Docs: man:nginx(8)
    Process: 2571583 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 2571585 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 2571642 (nginx)
      Tasks: 33 (limit: 153527)
     Memory: 60.3M (peak: 65.1M)
        CPU: 23.695s

Check Nginx is Serving Content

Nginx serves a default page on installation, you can check that by visiting your server’s IP address in a web browser:

text logo
http://your-server-ip

If you see the nginx default page, your nginx is installed and configured correctly, you are ready to start hosting your website/webservice on your server.

Managing Nginx Service

Like all other services managed by systemd, you can start, stop, restart, and reload the nginx service with the following commands:

To stop the nginx service:

bash logo
sudo systemctl stop nginx

To start the nginx service:

bash logo
sudo systemctl start nginx

To restart the nginx service:

bash logo
sudo systemctl restart nginx

To reload the nginx service (without downtime):

bash logo
sudo systemctl reload nginx

The reload command will reload the configuration files without stoping the service,very useful when you change configurations and do not want to cause downtime on all services served by nginx.

To stop nginx from running on boot, you can disable it with:

bash logo
sudo systemctl disable nginx

To make nginx start on boot, you can enable it with:

bash logo
sudo systemctl enable nginx

Next Steps

  1. Configuring Server blocks (Soon)
  2. Configuring SSL with Let’s Encrypt (Soon)
  3. Hardening Nginx (Soon)
  4. Performance Tuning Nginx (Soon)