Nginx is one of the most widely used web servers in the world, powering everything from small personal blogs to high-traffic production applications. If you’re setting up a new Linux server, learning how to install and configure Nginx on Ubuntu is one of the first — and most important — skills you’ll need.
In this guide, you’ll learn how to:
By the end, you’ll have a fully working Nginx installation ready to serve a static site or act as a reverse proxy for an application.
Before you begin, make sure you have:
Once those are in place, you’re ready to install Nginx.
Nginx is available directly from Ubuntu’s default package repositories, which makes installation straightforward using apt.
First, update your local package index so you’re installing the latest available version:
sudo apt update
Then install Nginx:
sudo apt install nginx -y
Once the installation finishes, Nginx starts automatically. You can confirm it’s running with:
sudo systemctl status nginx
You should see output showing the service as active (running).
If you’re running UFW (Uncomplicated Firewall) — which is common on Ubuntu servers — you’ll need to open a port so traffic can actually reach Nginx. When Nginx is installed, it automatically registers a few application profiles with UFW.
You can see them with:
sudo ufw app list
You should see output similar to:
Available applications:
Nginx Full
Nginx HTTP
Nginx HTTPS
OpenSSH
To allow HTTP, HTTPS, and SSH traffic, allow OpenSSH first, then Nginx Full:
sudo ufw allow OpenSSH
sudo ufw allow 'Nginx Full'
⚠️ Important: Always allow OpenSSH before enabling UFW. If you enable the firewall without an SSH rule in place, you'll lose your SSH connection and lock yourself out of the server.
Now enable UFW:
sudo ufw enable
Confirm the rules were added:
sudo ufw status
You should see OpenSSH and Nginx Full both allowed:
Status: active
To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
Nginx Full ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)
Nginx Full (v6) ALLOW Anywhere (v6)
💡 Opening port 443 here doesn’t mean HTTPS is working yet — Nginx isn’t actually listening on that port until you configure SSL. It just means the firewall is ready and you won’t need to revisit it later. We cover the SSL setup itself in Securing Nginx with Let’s Encrypt via Certbot.
With Nginx installed and the firewall configured, it’s time to confirm everything works by loading the default Nginx page in a browser.
First, grab your server’s public IP address and then open a browser and navigate to:
http://your_server_ip
You should see the default Nginx welcome page with the message “Welcome to nginx!” This confirms Nginx is installed correctly and reachable over the internet.
Now that Nginx is running, you’ll want to know how to control it. Nginx runs as a systemd service, so all the standard systemctl commands apply.
Stops the Nginx service
sudo systemctl stop nginx
Starts the Nginx service
sudo systemctl start nginx
Stops and restarts Nginx (drops active connections briefly)
sudo systemctl restart nginx
Reloads Nginx without dropping connections — use this after config changes
sudo systemctl reload nginx
Stops Nginx from starting automatically at boot
sudo systemctl disable nginx
Re-enables Nginx to start automatically at boot
sudo systemctl enable nginx
Now for the main event. Run Certbot with the Nginx plugin:
💡 Pro tip: Before reloading or restarting Nginx after a config change, always test the configuration for syntax errors first:
sudo nginx -t
If the test passes, you’ll see syntax is ok and test is successful — then it’s safe to reload.
Now that you know how to manage the Nginx service, it’s worth understanding where its files actually live on disk.
Content
Server Configuration
Log Files
You’ve now installed and configured Nginx on Ubuntu from the ground up — from installation and firewall rules to verifying it in the browser and understanding where its core files live. At this point, Nginx is ready to serve a static site or sit in front of an application as a reverse proxy.
From here, you might want to:

© 2026 Stackstroke. All rights reserved.