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.
bashsudo apt update sudo apt upgrade -y
Step 2 – Install Nginx
Install Nginx from Ubuntu's official repositories.
bashsudo apt install nginx -y
Step 3 – Verify Installation
Check that Nginx has been installed correctly.
bashnginx -v
Example output:
textnginx version: nginx/1.24.x
Step 4 – Start Nginx
If Nginx is not already running:
bashsudo systemctl start nginx
Verify the status:
bashsudo systemctl status nginx
You should see:
textActive: active (running)
Step 5 – Enable Nginx on Boot
Automatically start Nginx whenever the server reboots.
bashsudo systemctl enable nginx
Verify:
bashsystemctl is-enabled nginx
Expected output:
textenabled
Step 6 – Configure the Firewall
If UFW is installed, allow HTTP and HTTPS traffic.
bashsudo ufw allow 'Nginx Full'
Reload firewall rules.
bashsudo ufw reload
Verify:
bashsudo ufw status
Step 7 – Test the Web Server
Open your browser and visit:
texthttp://YOUR_SERVER_IP
If everything is working, you'll see the default Nginx welcome page.
Useful Commands
Restart Nginx:
bashsudo systemctl restart nginx
Reload configuration:
bashsudo systemctl reload nginx
Stop Nginx:
bashsudo systemctl stop nginx
Disable auto start:
bashsudo systemctl disable nginx
Troubleshooting
Port 80 Already in Use
Check which process is using the port.
bashsudo lsof -i :80
Test Configuration
Validate the configuration before restarting.
bashsudo nginx -t
View Error Logs
bashsudo 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.



