Thumbnail of Astro arcs.

Run the following commands:

  1. Create the site folder sudo mkdir -p /var/www/{your-domain}/

  2. Set your user as the folder owner sudo chown -R $USER:$USER /var/www/{your-domain}/

  3. Set permissions sudo chmod -R 755 /var/www/{your-domain}/

  4. Create a test index.html file sudo nano /var/www/{your-domain}/index.html

  5. index.html file content

<html>
    <head>
        <title>Welcome to your-domain!</title>
    </head>
    <body>
        <h1>Success!  The your-domain server block is working!</h1>
    </body>
</html>
  1. For NGINX to serve this content, create a new server block with the right directives. Instead of editing the default config directly, create a new file at /etc/nginx/sites-available/{your-domain}:

sudo nano /etc/nginx/sites-available/{your-domain}

  1. Configuration file content:
server {
        listen 80;
        listen [::]:80;

        root /var/www/your_domain;
        index index.html index.htm index.nginx-debian.html;

        server_name your_domain www.your_domain;

        location / {
                try_files $uri $uri/ =404;
        }
}
  1. Enable the file by creating a symlink to sites-enabled, which NGINX reads on startup:

sudo ln -s /etc/nginx/sites-available/your_domain /etc/nginx/sites-enabled/

NOTE: NGINX uses symbolic links (symlinks) to track which server blocks are enabled. Creating a symlink is like creating a shortcut: later, you can remove that shortcut from sites-enabled while keeping the original config in sites-available.

  1. To avoid potential hash bucket memory issues when adding additional server names, update one value in /etc/nginx/nginx.conf. Open the file:

sudo nano /etc/nginx/nginx.conf

Find the server_names_hash_bucket_size directive and remove # to uncomment the line. If you use nano, press CTRL + w to search quickly.

Check for config errors: sudo nginx -t

  1. Restart NGINX: sudo systemctl restart nginx

Happy reading! ☕

Comments