For a recent project, I moved to Caddy Server v2 for easy configuration and also as my app supported wildcard domains and Caddy was the easiest way to do this as well as configuring SSL automatically.
You can see my post on Caddy v2 and CloudFlare here
After deploying the app with Puma I ran into a few issues. The main one being that assets weren’t being loaded. This is because Puma is not a static web server so it wouldn’t send those files.
After a lot of head scratching and Googling, I managed to work out how to do it.
Here’s my Caddyfile
:
*.appname.com {
route /assets/* {
root /assets/* /home/deploy/appname/current/public
file_server
}
route /packs/* {
root /packs/* /home/deploy/appname/current/public
file_server
}
@notAssets {
not path /assets/* /packs/*
}
reverse_proxy @notAssets 127.0.0.1:1234
tls {
dns cloudflare <API-token>
}
}
As you can see, I map both /assets/*
and /packs/*
to the public
folder where the app is deployed. These 2 paths are then excluded
using the @notAssets
variable. You can name this to whatever
you want.
And that should be it!