Developers and DevOps engineers
How to Deploy an Nginx Site on a VM
Install Nginx, publish a static site, and configure a production-ready server block.
12 min read · Updated 2026-03-19
Prerequisites
- • Ubuntu VM created and reachable over SSH
- • Security group allows TCP 22 and TCP 80
- • Domain name optional but recommended
1. Install Nginx
Install the latest stable Nginx package from Ubuntu repositories and start the service.
Install and enable Nginx (bash)
sudo apt update
sudo apt -y install nginx
sudo systemctl enable --now nginxCheck service status (bash)
systemctl status nginx --no-pager2. Upload site files
Place static assets in a dedicated application directory and keep ownership with a non-root deploy user.
Create site directory (bash)
sudo mkdir -p /var/www/marketing-site/current
sudo chown -R ubuntu:ubuntu /var/www/marketing-siteSync local files (bash)
rsync -avz ./site/ ubuntu@<floating-ip>:/var/www/marketing-site/current/3. Configure server block
Create a site-specific Nginx config instead of editing the default config directly.
Nginx site config (nginx)
server {
listen 80;
server_name example.com www.example.com;
root /var/www/marketing-site/current;
index index.html;
location / {
try_files $uri $uri/ =404;
}
location ~ /\. {
deny all;
}
}Enable config and test (bash)
sudo ln -s /etc/nginx/sites-available/marketing /etc/nginx/sites-enabled/marketing
sudo nginx -t
sudo systemctl reload nginx4. Harden and add TLS
Use HTTPS for all external-facing services. Certbot offers quick certificate provisioning for Lets Encrypt.
Install and request certificate (bash)
sudo apt -y install certbot python3-certbot-nginx
sudo certbot --nginx -d example.com -d www.example.comOperator tips
- • Enable HTTP to HTTPS redirect in production.
- • Track certificate renewals with systemd timers.