Skip to content

Serve a VPS website with Nginx ​

This Ubuntu/Debian example serves a static site with Nginx. It creates an actual Nginx site configuration, not just a folder. Use a separate application runtime for PHP or Node.js.

Before you begin ​

Use sudo access, a backup of existing server configuration and a supported Ubuntu/Debian installation. On an existing server, review enabled sites and ports before adding anything. Do not overwrite another site’s files or configuration.

Steps ​

  1. Install Nginx from the system package source. Create an unused site directory and upload the production static files into it.

    bash
    sudo apt update
    sudo apt install nginx
    sudo mkdir -p /var/www/apnsite
  2. Create /etc/nginx/sites-available/apnsite with the example below. Replace the example domain and document root. The directory must contain the actual built entry file, not only source code.

    nginx
    server {
        listen 80;
        server_name example.com;
        root /var/www/apnsite;
        index index.html;
    
        location / {
            try_files $uri $uri/ =404;
        }
    }
  3. Enable this new site only if that filename is unused. Validate configuration before reloading. Do not reload a failed configuration.

    bash
    sudo ln -s /etc/nginx/sites-available/apnsite /etc/nginx/sites-enabled/apnsite
    sudo nginx -t
    sudo systemctl reload nginx
    curl -I -H "Host: example.com" http://127.0.0.1/
  4. Point the domain’s A/AAAA records at this server, then allow the web ports you need.

  5. Check the public HTTPS route, assets, nested pages and access policy. The static example returns 404 for unknown files; a client-side router may need an application-specific fallback.

  6. Review all active Nginx listeners and the firewall. The package’s existing default site can still listen on public ports. Keep only the listeners and inbound rules you intentionally need.

Hosting on a public IP ​

Configure a public listener and correct A/AAAA records, allow the required inbound ports and install a valid origin HTTPS certificate. Do not point DNS at a private or loopback address.

Last reviewed ​

2026-10-28