How to Install Nginx on Ubuntu 24.04
A clear, copy-paste guide to installing Nginx on Ubuntu 24.04, opening the firewall, and serving your first page over HTTP.

Nginx is the web server behind a huge share of the internet, and it is the natural first thing to install on a fresh Ubuntu 24.04 VPS. By the end of this guide you will have Nginx running, the firewall configured, and your first site served over HTTP — ready to add a domain and TLS.
Before you start
You need a VPS running Ubuntu 24.04 and a user with sudo rights. If you have not logged in yet, our walkthrough on the first 10 minutes on a new VPS covers creating a non-root user and basic hardening. Start by refreshing the package index:
sudo apt update && sudo apt upgrade -y
Install Nginx
Nginx is in the default Ubuntu repositories, so installation is a single command:
sudo apt install nginx -y
The package ships with a systemd service that starts automatically. Confirm it is running:
systemctl status nginx
You should see active (running) in green. If it is not enabled on boot, fix that with sudo systemctl enable --now nginx.
Open the firewall
If you follow good practice and run UFW — and you should, see our UFW firewall basics guide — Nginx registers application profiles you can allow by name:
sudo ufw app list
sudo ufw allow 'Nginx Full'
sudo ufw reload
Nginx Full opens both port 80 (HTTP) and 443 (HTTPS). If you only need HTTP for now, use Nginx HTTP instead.

Test it in a browser
Point your browser at your server's IP address (http://YOUR_SERVER_IP). You should see the default "Welcome to nginx!" page. That page is served from /var/www/html/index.nginx-debian.html.
Understand the file layout
Nginx on Ubuntu uses a clean split you will use constantly:
- Main config:
/etc/nginx/nginx.conf— global settings you rarely touch. - Site configs:
/etc/nginx/sites-available/— one file per site. - Enabled sites:
/etc/nginx/sites-enabled/— symlinks to the files you have switched on. - Web root:
/var/www/htmlby default. - Logs:
/var/log/nginx/access.loganderror.log.
Create your first server block
Rather than editing the default, create a dedicated config for your domain. Make a web root and a simple page:
sudo mkdir -p /var/www/example.com/html
echo '<h1>It works on Nxeon</h1>' | sudo tee /var/www/example.com/html/index.html
Now create /etc/nginx/sites-available/example.com:
server {
listen 80;
listen [::]:80;
server_name example.com www.example.com;
root /var/www/example.com/html;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
Enable the site by symlinking it, then remove the default so it does not shadow yours:
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo rm /etc/nginx/sites-enabled/default
Always test before you reload
The golden rule of Nginx: test the config for syntax errors before applying it. This one habit prevents most outages:
sudo nginx -t
sudo systemctl reload nginx
reload applies changes with zero dropped connections, unlike restart. If you point your domain's A record at the server (see how to point a domain to your VPS), your page will now answer on the domain name.
Add HTTPS next
Serving over plain HTTP is fine for testing, but every real site needs TLS. The easiest route is Certbot, which fetches a free certificate and rewrites your server block automatically — walk through it in our guide to getting a free SSL certificate with Certbot. Once Nginx is comfortable, the natural next step is putting it in front of an app: see how to set up Nginx as a reverse proxy.
Enable gzip and basic tuning
Out of the box Nginx serves uncompressed responses, which wastes bandwidth on text. Enable gzip in /etc/nginx/nginx.conf inside the http block:
gzip on;
gzip_comp_level 5;
gzip_types text/plain text/css application/json application/javascript application/xml image/svg+xml;
Two more settings pay off immediately. server_tokens off; hides your exact Nginx version from response headers, giving attackers less to work with. And raising worker_connections in the events block lets a single worker handle far more simultaneous clients:
events {
worker_connections 2048;
}
Validate and reload after any change with sudo nginx -t && sudo systemctl reload nginx. These small tweaks noticeably improve both speed and privacy, and they apply whether you serve static files or proxy an app.
FAQ
Is Nginx or Apache better on Ubuntu 24.04?
For static files and as a reverse proxy, Nginx generally uses less memory and handles high concurrency more predictably. Apache is more flexible with per-directory .htaccess rules and PHP via mod_php. Many people run Nginx and are happy; if you rely on .htaccess, read our Apache install guide.
Why do I still see the default Nginx page after adding my site?
You almost certainly left the default site enabled, so it wins on port 80. Remove /etc/nginx/sites-enabled/default, run sudo nginx -t, then reload.
How do I check what is wrong when Nginx will not start?
Run sudo nginx -t for config errors and sudo journalctl -u nginx -e for the service log. A common culprit is another process already bound to port 80 — find it with sudo ss -ltnp | grep :80.
Do I need to restart Nginx after every change?
No. Use sudo systemctl reload nginx for config changes; it applies them gracefully. Reserve restart for upgrades or when the master process itself needs to cycle.
Want the web server without the setup? Nxeon VPS plans give you full root on fast NVMe storage with one-click Ubuntu images, so you can install Nginx in minutes — or lean on our free migration help to move an existing site over.