Tutorials  /  Ubuntu

How to Install Nginx on Ubuntu 24.04 (Step-by-Step)

Ccentron Redaktion · December 2025 ·7 min read ·Ubuntu, Tutorial

Nginx is a free, open-source web server that helps you deliver static and dynamic websites, apps, or services. On Ubuntu, you can use Nginx as a classic web server, a load balancer, a reverse proxy, or an HTTP cache.

This guide walks you through installing Nginx on Ubuntu 24.04 and setting up example web applications so they run smoothly on your server.

Prerequisites

Before you begin:

  • Deploy an Ubuntu 24.04 instance on centron.
  • Create a new domain or subdomain A record that points to your server IP address. For example, app.example.com.
  • Access the server using SSH and create a non-root user with sudo privileges.
  • Update the server.
VM

Matching infrastructure at centron

Ubuntu servers without your own hardware: ccloud³ VMs with full root access from €3.12 per month, billed by the hour and ready in seconds. Rent a cloud server →

Install Nginx on Ubuntu 24.04

The newest Nginx package is included in the standard APT repositories for Ubuntu 24.04. Use the steps below to refresh your package lists and install the Nginx web server.

Update the package index

Update the server package index.

Console
$ sudo apt update

Install Nginx

Install Nginx.

Console
$ sudo apt install nginx -y

Verify the installed version

View the installed Nginx version on your server.

Console
$ sudo nginx -version

Your output should be similar to the one below:

Code
nginx version: nginx/1.24.0 (Ubuntu)

Manage the Nginx System Service

Nginx relies on a systemd service called nginx to control its runtime and worker processes. Follow these steps to enable and manage the service on your server.

Enable Nginx at boot

Enable the Nginx web server to start automatically at boot time.

Console
$ sudo systemctl enable nginx

Output:

Code
Synchronizing state of nginx.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable nginx

Start Nginx

Start the Nginx service.

Console
$ sudo systemctl start nginx

Stop Nginx

Stop the Nginx service.

Console
$ sudo systemctl stop nginx

Restart Nginx

Restart the Nginx service.

Console
$ sudo systemctl restart nginx

Check service status

View the Nginx service status and verify that it's running.

Console
$ sudo systemctl status nginx

Output:

YAML
● 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 2024-06-26 10:55:50 UTC; 1min 0s ago
       Docs: man:nginx(8)
    Process: 2397 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 2399 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 2400 (nginx)
      Tasks: 2 (limit: 1068)
     Memory: 1.7M (peak: 2.4M)
        CPU: 13ms
     CGroup: /system.slice/nginx.service
             ├─2400 "nginx: master process /usr/sbin/nginx -g daemon on; master_process on;"
             └─2401 "nginx: worker process"

If you see Active: active (running), then Nginx is running correctly. If the status shows Active: active (failed), stop anything else using HTTP port 80 and then restart the nginx service.

Create a New Nginx Virtual Host

Nginx virtual hosts let you serve application files from a dedicated folder under a chosen domain. Use the steps below to set up a simple virtual host that securely publishes an example application.

Create a virtual host configuration

Create a new Nginx virtual host configuration in the /etc/nginx/sites-available directory. For example, app.example.com.conf.

Console
$ sudo nano /etc/nginx/sites-available/app.example.com.conf

Add the following configurations to the file.

Code
server {
        listen 80;
        listen [::]:80;

        server_name app.example.com;

        root /var/www/app.example.com;
        index index.html;

        location / {
                try_files $uri $uri/ =404;
        }
}

Save and close the file.

This configuration listens on your app.example.com domain and serves files from the directory /var/www/app.example.com.

Test the configuration

Test the Nginx configuration for errors.

Console
$ sudo nginx -t

Output:

Code
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Enable the virtual host

Link the configuration to the /etc/nginx/sites-enabled directory to activate the virtual host on your server.

Console
$ sudo ln -s /etc/nginx/sites-available/app.example.com.conf /etc/nginx/sites-enabled/

Create the web root directory

Create a new web root directory /var/www/app.example.com to store your web application files.

Console
$ sudo mkdir -p /var/www/app.example.com

Add a sample HTML page

Create a new HTML application file within the directory. For example, index.html.

Console
$ sudo nano /var/www/app.example.com/index.html

Add the following HTML contents to the file.

Greetings from centron

Save and close the file.

When you open the page in a browser, this sample app shows a “Greetings from centron” heading.

Restart Nginx and test access

Restart Nginx to apply the new virtual host configurations on your server.

Console
$ sudo systemctl restart nginx

Access your domain to confirm that Nginx serves the virtual host files correctly. For example, test it with Curl.

Console
$ curl http://app.example.com

Output:

Code
Greetings from centron

Secure the Nginx Web Server with SSL

SSL certificates encrypt traffic between a browser and your Nginx server over HTTPS. By default, Nginx accepts requests on the unsecured HTTP port 80. Use the steps below to create trusted Let’s Encrypt certificates and protect your web server with HTTPS.

Install Certbot

Install the Certbot Let's Encrypt client package using Snap.

Console
$ sudo snap install --classic certbot

Check Certbot version

View the installed Certbot version on your server.

Console
$ sudo certbot --version

Output:

Code
certbot 2.11.0

Generate an SSL certificate

Generate a new SSL certificate for your domain. Replace app.example.com with the actual domain in your Nginx virtual host configurations.

Console
$ sudo certbot --nginx -d app.example.com --agree-tos

Set Up Firewall Rules

Ubuntu 24.04 includes Uncomplicated Firewall (UFW) enabled by default. Use the steps below to open HTTP and HTTPS ports for Nginx.

Allow HTTP traffic

Allow network connections on the HTTP port 80.

Console
$ sudo ufw allow 80/tcp

Allow HTTPS traffic

Allow connections on the HTTPS port 443.

Console
$ sudo ufw allow 443/tcp

Verify UFW rules

View the UFW table and verify that the new connection rules are active.

Console
$ sudo ufw status

Output:

Code
Status: active

To                         Action      From
--                         ------      ----
22/tcp                     ALLOW       Anywhere                  
80/tcp                     ALLOW       Anywhere                  
443/tcp                    ALLOW       Anywhere                  
22/tcp (v6)                ALLOW       Anywhere (v6)             
80/tcp (v6)                ALLOW       Anywhere (v6)             
443/tcp (v6)               ALLOW       Anywhere (v6)

Conclusion

You’ve installed Nginx on Ubuntu 24.04 and set it up to serve web applications from your server. With Nginx, you can run multiple virtual hosts to publish different apps securely under separate domains. You can also combine Nginx with services like MySQL and PHP to power dynamic applications. For additional features and tuning options, refer to the official Nginx documentation.

Jetzt 200 € Guthaben sichern

Testen Sie Ihr Setup auf ccloud³

Registrieren Sie sich in der ccloud³ und erhalten Sie 200 € Startguthaben für Ihr Projekt – z. B. für eine PostgreSQL-VM mit automatischen Backups.

centron Redaktion Technische Redaktion

Das Redaktionsteam von centron schreibt Anleitungen aus dem Betriebsalltag: getestet auf unserer eigenen Plattform, betrieben im Rechenzentrum in Hallstadt bei Bamberg.

Kategorie Ubuntu
Teilen
Noch offene Fragen?

Our team will help you with your specific setup - in German or English, by people who run the platform themselves.

War dieses Tutorial hilfreich?

Your answer is stored anonymously and helps us improve our tutorials.

Kommentare

No comments yet - be the first to ask a question about this tutorial.

Sign in to comment

Comments are open to centron customers. Sign in to your account to ask a question about this tutorial.

Weiterlesen

Das könnte Sie auch interessieren

Jetzt kostenlos anfangen

Melden Sie sich an und erhalten Sie in den ersten 60 Tagen ein Guthaben von 200 € bei centron.

Dieses Werbeangebot gilt nur für neue Konten. Angebot ausschließlich für Gewerbetreibende.

Jetzt loslegen Sales kontaktieren