Raspberry PI as a web server setup guide
Raspberry PIs are cheap. Static site generators result in sites which are easy to serve. Lets encrypt offers free SSL certificates and a great tool for managing them. Cloudflare has an API which can be used for dynamic dns, which is also free. £35 for one off website hosting with SSL is pretty cool. Note: You can use Netlify which offers hosting of your static site for free with SSL included. This is likely a good choice for a “real” website but if you have a pi lying around this is a fun little project.
Set a static IP on the PI to allow a port forwarding rule to be setup which will survive server reboots.
interface eth0 static ip_address=192.168.2.13/24 static routers=192.168.2.1 static domain_name_servers=220.127.116.11
Now setup 2 port forwarding rules on your router. One for port 80 and one for port 443. Normally your router will have a web interface where you can configure such things.
Install Nginx to serve your website. Its a relatively lightweight webserver unlike the more traditional apache.
sudo apt update sudo apt install -y nginx
Link your site to the default
sudo ln -s /home/user/yoursite /var/www/html
sudo apt-get install apt-transport-https ca-certificates software-properties-common -y curl -fsSL get.docker.com -o get-docker.sh && sh get-docker.sh sudo usermod -aG docker pi
Add the following to /etc/sources.list
deb https://download.docker.com/linux/raspbian/ stretch stable
sudo apt-get update sudo apt-get upgrade systemctl start docker.service
To check it is installed correctly.
Move your domain to cloudflare. This process might take 24-48 hours and initially involves opening an account, adding your domain, and then
Install cloudflare dynamic dns updater and run it via docker.
You need to also delete /etc/pip.conf as it will break lets encypt install process.
Open 80 and 443 on your router and setup port forwarding to your raspberry pi. Dont expect lightning performance but it is indeed a capable tool for serving static content. Who needs the ‘cloud’?!