HOWTO serve up web content in 2 seconds using BusyBox

#linux #howto #selfhosting

Here you are with your very own statically generated website. You want to get that puppy up but you definitely don't want to resort to something that's a huge chore like S3 buckets. Well i have a solution for you. It's called BusyBox.

That's right and you probably already have it.

Just one caveat here before i show you how simple this can be. You will probably want some form of reverse proxy for SSL. If you already have one or plan to use something like cloudflared then read on.

Most people don't realize this but BusyBox has it's own HTTPD server:

$ busybox httpd -f -p 9393

for example will run an httpd server serving up $PWD on 9393

$ curl localhost:9393 hello

So the simplest thing that could possibly work is to create a service file in /etc/systemd/system name it something like myweb.service and it would look like this:

[Unit]
Description=BusyBox HTTP Server
After=network.target

[Service]
Type=simple
User=root
WorkingDirectory=/var/www
ExecStart=/bin/busybox httpd -f -p 8000
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target

now you can just do this as root:

$ sudo systemctl enable —now myweb

now your site at /var/www should be being served up on 8000. This is where you want to utilize your reverse proxy if you're serving up some SSL. These are so light with a proxy in front of them you can easily run several for different domains and services without feeling a pinch.