Accessibilitech

Metodologías avanzadas para identificar, evaluar y transferir soluciones innovadoras para la accesibilidad de personas con discapacidad

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

 

Install Nginx Web Server on Ubuntu 24.04

Nginx is a powerful, high-performance web server that’s widely used across the globe for serving static content, acting as a reverse proxy, and load balancing. Its efficiency and lightweight nature make it a popular choice among developers and system administrators alike. Ubuntu 24.04, the latest LTS (Long-Term Support) release from Canonical, offers improved performance, security, and updated software packages. This guide will walk you through the steps to install Nginx Web Server on Ubuntu 24.04.

Whether you’re building a simple website or deploying a full-stack application, installing Nginx on Ubuntu is a foundational task that ensures your server can handle web traffic effectively. In this tutorial, we’ll cover everything from updating your system to starting and managing the Nginx service.

Step 1: Update Your System

Before you install any software, it’s always a good idea to update your system’s package index. This ensures that all packages and dependencies are up to date.

sudo apt update
sudo apt upgrade -y

These commands fetch the latest package list and apply updates to installed software. Keeping your system updated is essential for security and stability, especially before major installations like Nginx.

Step 2: Install Nginx Web Server

Installing Nginx on Ubuntu 24.04 is straightforward, thanks to the built-in package repositories that include the latest stable version of Nginx.

sudo apt install nginx -y

The -y flag automatically confirms the installation prompt. Once the command executes, Nginx and all necessary dependencies will be installed.

Step 3: Verify Nginx Installation

Once the installation is complete, it’s important to check if the Nginx web server is running. You can do this with the systemctl command:

sudo systemctl status nginx

If the output shows that Nginx is active and running, the installation was successful. You can also open your browser and visit your server’s IP address:

http://your_server_ip

If everything is set up correctly, you should see the default Nginx welcome page. This indicates that the Nginx web server is serving HTTP requests correctly.

Step 4: Manage the Nginx Service

Nginx, like other services in Ubuntu, can be managed using systemctl. Here are some basic commands to control the Nginx service:

  • Start Nginx:
sudo systemctl start nginx
  • Stop Nginx:
sudo systemctl stop nginx
  • Restart Nginx:
sudo systemctl restart nginx
  • Reload Configuration (without downtime):
sudo systemctl reload nginx
  • Enable Nginx to Start at Boot:
sudo systemctl enable nginx

These commands give you full control over the Nginx service, allowing you to start, stop, or reload the server as needed.

Step 5: Configure Firewall (Optional but Recommended)

If you have a firewall enabled on your Ubuntu 24.04 server, you’ll need to allow traffic on HTTP (port 80) and HTTPS (port 443). Ubuntu uses UFW (Uncomplicated Firewall) by default.

First, check if UFW is enabled:

sudo ufw status

If it’s active, allow Nginx through the firewall:

sudo ufw allow 'Nginx Full'

This command opens both port 80 (HTTP) and 443 (HTTPS) for incoming web traffic.

Step 6: Basic Configuration of Nginx

Nginx configuration files are stored in the /etc/nginx directory. The main configuration file is:

/etc/nginx/nginx.conf

Each website or application hosted by Nginx is typically configured in a separate file located in:

/etc/nginx/sites-available/

You can create a new configuration file in sites-available, then link it to sites-enabled using:

sudo ln -s /etc/nginx/sites-available/your_site /etc/nginx/sites-enabled/

Always test your configuration after making changes:

sudo nginx -t

If the syntax is OK, reload Nginx to apply the changes:

sudo systemctl reload nginx

Step 7: Install SSL (Optional for HTTPS)

To secure your site using HTTPS, you can install a free SSL certificate from Let’s Encrypt. Start by installing Certbot:

sudo apt install certbot python3-certbot-nginx -y

Then run Certbot with the Nginx plugin:

sudo certbot --nginx

Follow the prompts to set up SSL automatically. Certbot will configure Nginx and obtain an SSL certificate for your domain.

Conclusion

Installing Nginx on Ubuntu 24.04 is a simple but powerful step in deploying your website or application. This guide walked you through updating your system, installing Nginx, configuring the firewall, and setting up SSL for secure communication. Whether you’re just learning how to install Nginx on Ubuntu or deploying in production, this foundational knowledge will help you manage your server efficiently.

0 views

Dejar un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *