Install Nginx on Ubuntu and serve a site
Updated 27 Nov 2026 nginx ubuntu
Set up a web server and a first virtual host.
Install
sudo apt update
sudo apt install -y nginx
systemctl status nginx
Create a site
sudo mkdir -p /var/www/example
echo "<h1>It works</h1>" | sudo tee /var/www/example/index.html
Create /etc/nginx/sites-available/example:
server {
listen 80;
server_name example.com;
root /var/www/example;
index index.html;
}
On a shared-IPv4 plan, replace 80 with one of your forwarded ports. Read Shared IPv4 and port forwarding first.
Enable it
sudo ln -s /etc/nginx/sites-available/example /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
sudo ufw allow "Nginx HTTP"
HTTPS (dedicated IPv4)
Point your domain's A record at the server, then:
sudo apt install -y certbot python3-certbot-nginx
sudo ufw allow "Nginx Full"
sudo certbot --nginx -d example.com