Need to migrate your e-mails to a new server? Free and paid versions of our online tool available.
Hero Image

Configure Nginx Virtual Hosts on Ubuntu 24.04

Configure Nginx Virtual Hosts on Ubuntu 24.04

Step 1 – Create the document root

mkdir -p /var/www/example.com/html
echo '<h1>Works!</h1>' > /var/www/example.com/html/index.html

Step 2 – Create /etc/nginx/sites-available/example.com

server {
    listen 80;
    listen [::]:80;
    server_name example.com www.example.com;
    root /var/www/example.com/html;
    index index.html index.php;
    access_log /var/log/nginx/example.com.access.log;
    error_log  /var/log/nginx/example.com.error.log;
    location / {
        try_files $uri $uri/ =404;
    }
}

Step 3 – Enable and reload

ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
nginx -t && systemctl reload nginx
nginx -t && systemctl reload nginx

Step 4 – Verify

curl -H 'Host: example.com' http://localhost