Quick static hosting

The goal was to be able to share files with friends, hosted on my raspberry pi. Here's the checklist:

DNS and port forwarding

Hopefully my ISP doesn't change the IP of my box (or rarely enough). So this is simply about adding a new A record to the result of curl ifconfig.co.

Next, connect to the box's management software, usually it's on 192.168.0.1, or whatever is the gateway IP for the network. Then enable forwarding port 80 and 443 to the IP assigned to the raspberry pi.

Extend lighttpd server

Since pi-hole already has lighttpd bound to the port 80, it needs to be extended with additional config. In order to avoid clashes with the installer and the existing server, everything must be placed in /etc/lighttpd/external.conf.

Let's put the root of this static hosting under /home/pi/static_nas/files/

These files should be somewhat private, so let's put a robots.txt at the root:

User-agent: *
Disallow: /

Add basic auth

Again, since these files are not meant to be shared to everyone, some auth is required. Let's go with the simplest thing: basic auth (RFC). Browsers will prompt for a username and password and transmit that in an http header. This is absolutely not secure unless tls is used. That's the next step.

And the file for users under /home/pi/nas/users.txt. It is placed outside the document-root directory so there is no way to get it through the web server.

arandomuser:secretpassword

Add letsencrypt

Basic auth is null and void without tls, so let's set that up. I used acme-tiny. The README is straightforward.

Let's create a new user and group to interact with letsencrypt.

sudo groupadd letsencrypt
sudo mkdir -p /etc/letsencrypt
sudo useradd -g letsencrypt --home-dir /etc/letsencrypt letsencrypt
sudo chown letsencrypt:letsencrypt /etc/letsencrypt
sudo mkdir -p /var/www/challenges
sudo chown letsencrypt:letsencrypt /var/www/challenges

The private key for the certificate is domain.key, the chained certificate given by letsencrypt is signed_chain.crt, and all of that is placed under /etc/letsencrypt/. The ssl configuration for lighttpd follows:

And that's it. I still need to figure out exactly how to reload lighttpd from the cron task when I renew the certificate. If possible, I'd rather avoid giving root access to this cron.