Guides

How to Set Up Nginx and Serve Your First Website

Install Nginx, put a real page on your domain, and add a free HTTPS certificate. About fifteen minutes from a bare server to a live site.

Virtualized Team·August 22, 2026·4 min read
How to Set Up Nginx and Serve Your First Website

Nginx is the web server behind a large share of the internet, and getting a static site online with it takes about fifteen minutes. This guide goes from a bare VPS to a working HTTPS site on your own domain.

Before you start

You need SSH access to your server, a user with sudo, and a domain already pointing at your server's IP. If DNS is not set up yet, do that first, because the HTTPS step at the end will fail without it.

Step 1: Open ports 80 and 443

Do this before installing anything, since firewall rules take a few minutes to propagate and you may as well let them do that while you work.

In the client portal, open Services, then Firewall Manager. Select your IP and create two rules: protocol TCP, destination port 80, Whitelist; then the same again for port 443. Port 80 handles plain HTTP and the certificate check, port 443 handles HTTPS. You need both.

Step 2: Install Nginx

On Ubuntu or Debian:

sudo apt update && sudo apt install nginx -y

On AlmaLinux or Rocky:

sudo dnf install nginx -y
sudo systemctl enable --now nginx

Visit your server's IP in a browser. You should see the default Nginx welcome page. If you do, the server is running and the firewall rule has gone live.

Step 3: Create a directory for your site

Keep your site out of the default location so upgrades to Nginx never touch your files:

sudo mkdir -p /var/www/example.com
sudo chown -R $USER:$USER /var/www/example.com

That chown means you can upload files as your normal user later without fighting permissions.

Put something in it:

nano /var/www/example.com/index.html
<!DOCTYPE html>
<html>
  <head><title>It works</title></head>
  <body><h1>Hello from my VPS</h1></body>
</html>

Step 4: Write a server block

A server block tells Nginx which domain maps to which directory. Create one:

sudo nano /etc/nginx/sites-available/example.com
server {
    listen 80;
    listen [::]:80;

    server_name example.com www.example.com;
    root /var/www/example.com;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }
}

Replace example.com with your actual domain in all three places.

On AlmaLinux and Rocky there is no sites-available directory. Put the file in /etc/nginx/conf.d/example.com.conf instead and skip the next step.

Step 5: Enable the site

On Ubuntu and Debian, enabling a site means symlinking it into sites-enabled:

sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/

Remove the default site so it does not answer for your domain instead:

sudo rm /etc/nginx/sites-enabled/default

Test the configuration before reloading. This catches typos before they take your site offline:

sudo nginx -t

If it says the syntax is ok and the test is successful, reload:

sudo systemctl reload nginx

Visit your domain. You should see your page.

Step 6: Add HTTPS

Certbot gets a free certificate from Let's Encrypt and configures Nginx to use it, all in one command.

On Ubuntu or Debian:

sudo apt install certbot python3-certbot-nginx -y

On AlmaLinux or Rocky:

sudo dnf install certbot python3-certbot-nginx -y

Then run it:

sudo certbot --nginx -d example.com -d www.example.com

Certbot asks for an email address for expiry warnings, asks you to accept the terms, and offers to redirect HTTP traffic to HTTPS. Say yes to the redirect.

It then edits your server block, adds the certificate, and reloads Nginx. Visit your domain again and it should load over HTTPS with a padlock.

Certificates last 90 days and renew automatically, since the installer sets up a timer for it. Confirm the renewal works without waiting three months:

sudo certbot renew --dry-run

If something goes wrong

nginx -t fails. The error names the file and line number. It is nearly always a missing semicolon or an unclosed brace.

Your domain shows the default Nginx page. Either the default site is still enabled, or server_name does not match the domain you typed. Remove the default and check for a typo.

Certbot fails with "Timeout during connect". Port 80 is not reaching your server. Let's Encrypt has to connect inbound to verify you control the domain, so the firewall rule must be live and DNS must already resolve to your IP. Check with dig example.com +short.

Certbot fails with "DNS problem: NXDOMAIN". The domain does not resolve at all yet. Wait for DNS to propagate and run it again.

403 Forbidden. Nginx cannot read your files. Confirm root points at the right directory and that an index.html actually exists there.

What next

You have a static site. If you want an application behind it instead, the usual pattern is to run your app on a local port and add a proxy_pass to that port inside the location block, then keep it running with systemd so it survives reboots.