Paridhi SolutionsBlog
Magento

How to Install Nginx on Ubuntu 24.04 for Magento 2

Complete step-by-step guide to installing and configuring Nginx on Ubuntu 24.04 for Magento 2. Learn installation, firewall setup, service management, and verification.

Paridhi Solutions
2026-06-30
2 min read read
How to Install Nginx on Ubuntu 24.04 for Magento 2

How to Install Nginx on Ubuntu 24.04

Nginx is a high-performance web server and reverse proxy that powers many Magento stores. It is lightweight, efficient, and capable of handling thousands of concurrent connections.

This guide explains how to install and configure Nginx on Ubuntu 24.04 as the web server for Magento 2.


Prerequisites

Before you begin, ensure that you have:

  • Ubuntu 24.04 installed
  • A user with sudo privileges
  • Internet connectivity
  • Updated package repository

Step 1 – Update Ubuntu

Always update your server before installing new packages.

bash
sudo apt update
sudo apt upgrade -y

Step 2 – Install Nginx

Install Nginx from Ubuntu's official repositories.

bash
sudo apt install nginx -y

Step 3 – Verify Installation

Check that Nginx has been installed correctly.

bash
nginx -v

Example output:

text
nginx version: nginx/1.24.x

Step 4 – Start Nginx

If Nginx is not already running:

bash
sudo systemctl start nginx

Verify the status:

bash
sudo systemctl status nginx

You should see:

text
Active: active (running)

Step 5 – Enable Nginx on Boot

Automatically start Nginx whenever the server reboots.

bash
sudo systemctl enable nginx

Verify:

bash
systemctl is-enabled nginx

Expected output:

text
enabled

Step 6 – Configure the Firewall

If UFW is installed, allow HTTP and HTTPS traffic.

bash
sudo ufw allow 'Nginx Full'

Reload firewall rules.

bash
sudo ufw reload

Verify:

bash
sudo ufw status

Step 7 – Test the Web Server

Open your browser and visit:

text
http://YOUR_SERVER_IP

If everything is working, you'll see the default Nginx welcome page.


Useful Commands

Restart Nginx:

bash
sudo systemctl restart nginx

Reload configuration:

bash
sudo systemctl reload nginx

Stop Nginx:

bash
sudo systemctl stop nginx

Disable auto start:

bash
sudo systemctl disable nginx

Troubleshooting

Port 80 Already in Use

Check which process is using the port.

bash
sudo lsof -i :80

Test Configuration

Validate the configuration before restarting.

bash
sudo nginx -t

View Error Logs

bash
sudo tail -f /var/log/nginx/error.log

Conclusion

Nginx is now installed and ready to host your Magento application. In the next tutorial, we'll install PHP 8.4 and all required extensions for Magento 2.

Tags

MagentoUbuntuNginxLinuxServer

Written by

Paridhi Solutions

Publishing in-depth tutorials, coding guides, and best practices for modern web development.

Visit Website →

Share this article

Related Articles