Due to Phil’s post on his wiki about Self Hosting Images I reached out to him how he had set it up and then realized I had already done something similar but forgot about it.
So without further explanation I’m listing out the steps I took to set up the NGinx Directory Index Listing.
On a DigitalOcean droplet (or any Ubuntu/Linux VPS) already set up with Nginx (if you need instructions for setting up NGinx Firewall access, follow steps 12-14 here), follow these steps:
- Get a domain or subdomain for the new site. In this example I used static.domain.com
- To restrict its access you can create a new folder in the home directory of your user profile (
mkdir public
), for example mine is/home/username/public
- While SSH’d into the VPS, navigate to
/etc/nginx/sites-available/
then createstatic.domain.com
by enteringsudo nano static.domain.com
- In the File put the following (make sure to change the path in root to your path)
server {
server_name static.domain.com;
root /home/username/public;
autoindex on;
autoindex_exact_size off;
autoindex_format html;
autoindex_localtime on;
}
- Change the
server_name
field to your domain name - Make sure to change the path in root to your path
- Next you need to enable the site via Symbolic link:
sudo ln -s /etc/nginx/sites-available/static.domain.com /etc/nginx/sites-enabled/ - Symbolic links site to enabled
- For an SSL Cert if you have cert bot install you can skip to step 9, otherwise continue to 7
- Enter
sudo apt install certbot - Install Certbot
- Enter
sudo apt-get install python-certbot-nginx
- Installs Nginx Certbot - Enter
sudo certbot --nginx
- Create HTTPS cert with Let’s Encrypt- Select whichever domains you want your cert to cover
- Press 2 to redirect HTTP traffic to HTTPS, this is recommended
- The conf files for your selected domains will be updated with the cert information automatically
You should now be able to access your NGinx directory index at static.domain.com
while any folders inside that directory will now be accessible at static.domain.com/folder/
Sources: