Bobcares

How to Install Nginx Web Server on Ubuntu 24.04

by | Mar 4, 2025

Learn how to install the Nginx Web Server on Ubuntu 24.04. Our Nginx Support team is here to help you with your questions and concerns.

How to Install Nginx Web Server on Ubuntu 24.04

How to Install Nginx Web Server on Ubuntu 24.04Nginx is a powerful and efficient web server widely used to serve web applications, act as a reverse proxy, and handle load balancing.

Today, we will install Nginx on Ubuntu 24.04, configure virtual hosts, and set up firewall rules.

Step 1: Install Nginx

  1. First, run the following command to make sure the server’s package index is up to date:
    sudo apt updateCopy Code
  2. Then, install the Nginx web server with:
    sudo apt install nginx -yCopy Code
  3. Now, check the installed Nginx version:
    sudo nginx -versionCopy Code
  4. The output should look similar to this:
    nginx version: nginx/1.24.0 (Ubuntu)Copy Code

Step 2: Manage Nginx System Service

Nginx uses `systemd` for service management. Here’s how to control Nginx processes:

  1. Ensure Nginx starts automatically when the server reboots:
    sudo systemctl enable nginxCopy Code
  2. Then, manually start the Nginx service:
    sudo systemctl start nginxCopy Code
  3. To stop the Nginx service:
    sudo systemctl stop nginxCopy Code
  4. Then, apply configuration changes by restarting Nginx:
    sudo systemctl restart nginxCopy Code
  5. Next, confirm Nginx is running:
    sudo systemctl status nginxCopy Code

Step 3: Configure Nginx Virtual Hosts

Virtual hosts allow Nginx to serve multiple domains or applications from a single server. Let’s create a new virtual host.

  1. First, create a new configuration file, for example, `app.example.com.conf`:
    sudo nano /etc/nginx/sites-available/app.example.com.confCopy Code
  2. Then, add the following content:
    
    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;
    }
    }
    Copy Code
  3. Then, save and close the file.
  4. Now, it is time to validate the Nginx configuration:
    sudo nginx -tCopy Code

    Successful output will look like this:
    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/nginx.conf test is successful
    Copy Code
  5. Then, link the configuration file to the `sites-enabled` directory:
    sudo ln -s /etc/nginx/sites-available/app.example.com.conf /etc/nginx/sites-enabled/Copy Code
  6. Next, create the directory to store the web application files:
    sudo mkdir -p /var/www/app.example.comCopy Code
  7. Now, create an `index.html` file for testing:
    sudo nano /var/www/app.example.com/index.htmlCopy Code

    Add this sample HTML:

    
    <html>
    <head></head>
    <body>
    <h1>Greetings from Vultr</h1>
    </body>
    </html>
    Copy Code
  8. Then, save and close the file.
  9. Now, apply the new virtual host configuration:
    sudo systemctl restart nginxCopy Code
  10. Confirm Nginx serves the virtual host:
    curl http://app.example.comCopy Code

    The output should display:

    Greetings from VultrCopy Code

Step 4: Configure Firewall Rules

  1. Enable HTTP (port 80):
    sudo ufw allow 80/tcpCopy Code
  2. Enable HTTPS (port 443):
    sudo ufw allow 443/tcpCopy Code
  3. Check active firewall rules:
    sudo ufw statusCopy Code

[Need assistance with a different issue? Our team is available 24/7.]

Conclusion

In brief, our Support Experts demonstrated how to fix the “configmap aws-auth does not exist” error in Amazon EKS with Terraform.

0 Comments

Submit a Comment

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

Speed issues driving customers away?
We’ve got your back!