Skip to content

Instantly share code, notes, and snippets.

@Xantios
Last active December 25, 2023 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Xantios/285e89abc1dc3ffbe91be297989893b7 to your computer and use it in GitHub Desktop.
Save Xantios/285e89abc1dc3ffbe91be297989893b7 to your computer and use it in GitHub Desktop.
Caddy on FreeBSD / OPNSense

A short intro

FreeBSD is nice and all, but editing files on it sucks (and i want to keep my firewall kinda clean) so lets get Mutagen up and running first

mkdir caddy
cd caddy
mutagen sync create --name Caddy . root@10.0.0.254:~/caddy/

( when you are done with this, feel free to delete it using mutagen sync terminate Caddy)

Download caddy for FreeBSD from caddyserver.com and put it in the caddy folder we created

Caddyfile

Configuring caddy is easy peasy lemon squezy! here is an example

{
	debug

	## If you want to use sslh to map forwards, change the ssl port
	# https_port 4431
}

host1.proudlySelfHosted.tld {
	reverse_proxy 10.0.0.1:8080 {
		# Extra config goes here
	}
}

# This host has SSL but its crappy so fix it
host2.alsoSelfHosted.tld {
	reverse_proxy 10.0.0.1:443 {
        transport http {
            tls_insecure_skip_verify
        }
	}
}

put this into the caddy folder to

SystemD can suck my rc.d

here is a quick script to get caddy into the service system of FreeBSD

#!/bin/sh

# $FreeBSD$
#
# PROVIDE: caddy
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add these lines to /etc/rc.conf.local or /etc/rc.conf
# to enable this service:
#
# caddy_enable (bool):	Set to YES by default.
#				Set it to NO to disable caddy.
# caddy_config (path):	Set to /root/caddy/Caddyfile
#				by default.

. /etc/rc.subr

name=caddy
rcvar=caddy_enable

load_rc_config $name

: ${caddy_enable:="YES"}
: ${caddy_config="/root/caddy/Caddyfile"}

command="/root/caddy/caddy"
command_args="start --config ${caddy_config}"

run_rc_command "$1"

Make sure Caddy starts & restarts

now SSH to your box (hit 8 for terminal) and run caddy start --config /root/caddy/Caddyfile to test it :-) if all is fine (which it should be) run

service enable caddy && service start caddy

Done and done! Marry X-Mas!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment