Where to put html files for nginx to serve
Summary
nginx cannot access files in a user’s home directory by default. Create a link from /var/www/<website_name> to the location of your website files and update the nginx .conf file accordingly.
The Problem
I installed nginx to serve my website to localhost for development and testing. I repeatedly got a ‘403 forbidden’ message when I tried to view localhost on my browser. The log files confirmed that nginx could not access the index.html file which is required to display the website. I use Debian.
The solution
When I copied the website files to /var/www/example_website and updated the nginx conf file so that the root location was this folder, the site displayed. So I created a soft link from the /var/www directory to the folder containing my html files:
sudo ln -s /home/demo/sites/example.com/public_html /var/www/example_site
Edit the .conf file to reflect the new root location:
root /var/www/example_site
index index.php index.htm index.html;
Restart the nginx process:
sudo systemctl restart nginx
Explanation
A little more searching on t’net found an obvious explanation. For security, nginx cannot serve files from your home directory. This is to prevent nefarious actors from using web-shenanigans to access files in this folder.