How To Install Nginx on Ubuntu 24.04
Updated on September 11, 2025 • Tutorial
Introduction
Nginx is one of the most popular web servers in the world, powering over 33% of all websites globally. It’s responsible for hosting some of the largest and highest-traffic sites on the internet, including Netflix, Pinterest, and Airbnb.
Nginx is a lightweight, high-performance choice that excels as both a web server and reverse proxy. In this guide, you’ll learn how to install and configure Nginx on Ubuntu 24.04.
Prerequisites
- Ubuntu 24.04 server with a regular, non-root user with sudo privileges
- UFW firewall configured
- Optional: A registered domain name pointed to your server
Installing Nginx
Nginx is available in Ubuntu’s default repositories, making installation straightforward. First, update your package index:
sudo apt update
sudo apt upgrade -y
Now install Nginx:
sudo apt install nginx -y
Adjusting the Firewall
Before testing Nginx, you need to adjust the firewall to allow access to the service. Nginx registers itself as a service with ufw upon installation.
List the available application configurations:
sudo ufw app list
Output:
Available applications:
Nginx Full
Nginx HTTP
Nginx HTTPS
OpenSSH
Profile meanings:
• Nginx Full: Opens both port 80 (HTTP) and 443 (HTTPS)
• Nginx HTTP: Opens only port 80 (normal, unencrypted traffic)
• Nginx HTTPS: Opens only port 443 (TLS/SSL encrypted traffic)
For now, allow HTTP traffic:
sudo ufw allow 'Nginx HTTP'
Verify the change:
sudo ufw status
Checking the Web Server
Ubuntu 24.04 starts Nginx automatically after installation. Check the status:
sudo systemctl status nginx
You should see active (running) in the output. Access your server’s IP in a browser to see the default Nginx landing page:
http://your_server_ip
Managing the Nginx Process
Here are the essential commands for managing Nginx:
# Stop the web server
sudo systemctl stop nginx
# Start the web server
sudo systemctl start nginx
# Restart the web server
sudo systemctl restart nginx
# Reload config without dropping connections
sudo systemctl reload nginx
# Disable auto-start on boot
sudo systemctl disable nginx
# Enable auto-start on boot
sudo systemctl enable nginx
Setting Up Server Blocks
Server blocks (similar to Apache virtual hosts) allow you to host multiple domains on one server. Create a directory for your domain:
sudo mkdir -p /var/www/your_domain/html
sudo chown -R $USER:$USER /var/www/your_domain/html
sudo chmod -R 755 /var/www/your_domain
Create a sample index page:
nano /var/www/your_domain/html/index.html
Create the server block configuration:
sudo nano /etc/nginx/sites-available/your_domain
Add this configuration:
server {
listen 80;
listen [::]:80;
root /var/www/your_domain/html;
index index.html index.htm index.nginx-debian.html;
server_name your_domain www.your_domain;
location / {
try_files $uri $uri/ =404;
}
}
Enable the site and test the configuration:
sudo ln -s /etc/nginx/sites-available/your_domain /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx
Important Nginx Files and Directories
Content
/var/www/html– Default web content location
Server Configuration
/etc/nginx– Nginx configuration directory/etc/nginx/nginx.conf– Main configuration file/etc/nginx/sites-available/– Per-site server blocks/etc/nginx/sites-enabled/– Enabled server blocks (symlinks)
Server Logs
/var/log/nginx/access.log– Every request to your server/var/log/nginx/error.log– Nginx errors
Conclusion
You now have Nginx installed and configured on your Ubuntu 24.04 server. You’re ready to serve content and can use Nginx as a foundation for many other technologies.
- ✓ Nginx installed and running
- ✓ Firewall configured for HTTP traffic
- ✓ Server blocks ready for multiple domains
- ✓ Essential management commands mastered
Next Steps: Consider securing your server with SSL/TLS using Let’s Encrypt Certbot for free HTTPS certificates.