I’ve recently moved a bunch of containers off my Raspberry Pi to an HP EliteDesk. For extra challenge points, I also decided to drop the venerable combination of Portainer and Nginx Proxy Manager for something else. Principally, all I care about is being able to easily self host various web apps on my home server, make them accessible to the outside world, and in some cases gate them behind a consistent login page - so here is what I did!
I’ve chosen Dockge for container management, caddy-docker-proxy
to forward requests from my router to the respective container, and nforwardauth
to provide the login gate.
In my case, Dockge was deployed using Docker into an LXC host running Debian. Once running, the remaining containers were created directly via the Dockge UI.
Firstly, we have caddy-docker-proxy
, which spins up Caddy and sets up forwarding rules based on container service labels. I expose ports 80 and 443 here, which receive HTTP(S) requests forwarded from my home router:
|
|
Secondly, the nforwardauth
instance, which handles authenticating users. It’s important to set the domain names correctly, and even more important to use a good, long and secure token secret string.
It’s also necessary to generate a passwd
file specifying the permitted usernames and passwords. In my case, I connected to my Dockge host with SSH and used mkpasswd
to populate /opt/dockge/stacks/nforwardauth/passwd
.
|
|
Finally, an example demonstrating how to bind it all together. Note the caddy
labels, which are used to set up the subdomain forwarding and require user authentication:
|
|
With this all set up and running, accessing whoami.example.com
will redirect you to auth.example.com
and require you to use a username/password combination from the passwd
file configured earlier. The really neat thing is that you only need to do this once - you won’t be re-prompted for any additional services you create.
Additionally, the username of the ‘current’ user is provided within a signed cookie value, so a service can theoretically use these data to bypass their own login system. (Just make sure to verify it first!)
I’ve been using this setup for a few weeks now, and it’s been working great so far.