Setting Up a Basic Website with NGINX
A basic NGINX website setup is perfect for HTML sites, landing pages, documentation pages, download areas, and simple business websites. The main idea is simple: create a folder for the site, place your files inside it, then tell NGINX which domain should serve that folder.
Step 1: Create the document root:
sudo mkdir -p /var/www/mywebsite/public
Step 2: Set sensible ownership. On many Ubuntu servers, www-data is the web server user:
sudo chown -R www-data:www-data /var/www/mywebsite
Step 3: Add a test page:
sudo nano /var/www/mywebsite/public/index.html
Add a simple message such as “My NGINX website is working” and save the file.
Step 4: Create a server block:
sudo nano /etc/nginx/sites-available/mywebsite
Inside the file, define your domain, root folder, and index files. The server_name should match your domain or subdomain.
Step 5: Enable the site:
sudo ln -s /etc/nginx/sites-available/mywebsite /etc/nginx/sites-enabled/
Step 6: Test the configuration:
sudo nginx -t
Step 7: Reload NGINX:
sudo systemctl reload nginx
Step 8: Point your domain DNS A record to the VPS IP address. Once DNS has updated, your website should load from the domain.
If you get a 403 forbidden error, check folder permissions and confirm an index.html or index.php file exists. If you see the wrong website, check your server_name values and run:
sudo nginx -T | grep server_name
This helps confirm which domain rules NGINX has loaded.