Need help having a caddy file that can redirect to a maintenance page when the primary site is down

1. The problem I’m having:

Everything is functional but when I do maintenance I would like to start another docker container that displays a status message backup in progress/site maintenance during certain times during the day.

2. Error messages and/or full log output:


3. Caddy version:

Latest docker image (caddy:latest)

4. How I installed and ran Caddy:

Docker compose. Everything including lemmy runs on docker, all is docker everywhere. Nothing is not a docker image.

a. System environment:

Debian 12 with docker compose.

b. Command:

Docker compose file, no issue here.

d. My complete Caddy config:

(caddy-common) {
        encode gzip
        header {
                Strict-Transport-Security "max-age=31536000; include-subdomains;"
                X-XSS-Protection "1; mode=block"
                X-Frame-Options "DENY"
                X-Content-Type-Options nosniff
                Referrer-Policy no-referrer-when-downgrade
                X-Robots-Tag "none"

        import caddy-common
        reverse_proxy http://lemmy-ui:1234

        @lemmy {
                path /api/*
                path /pictrs/*
                path /feeds/*
                path /nodeinfo/*
                path /.well-known/*

        @lemmy-hdr {
                header Accept application/*

        handle @lemmy {
                reverse_proxy http://lemmy:8536

        handle @lemmy-hdr {
                reverse_proxy http://lemmy:8536

        @lemmy-post {
                method POST

        handle @lemmy-post {
                reverse_proxy http://lemmy:8536

5. Links to relevant resources:

What I would like to have the option to do is to bring down the lemmy UI website and backend running postgres and then bring up this docker container:

I am able to start this docker container on port 8080 and display a maintenance page, but the issue is I need caddy in front as this has the SSL certificate for port 443 and redirect from port 80.

I want caddy to be able to fall over to this site on port 8080 if lemmy is down for maintenance so that during the backup window instead of the site being dead, the docker with the maintenance page on port 8080 is displaed instead with the ssl certificate on port 443.

Is this possible to complete? I am stuck. I dont know if this is possible and unsure how to proceed.

Thank you to anyone who is able to help.

Kind regards

Yeah, you can configure your reverse_proxy with health checking and configure a second upstream pointing to your maintenance container, and set the load balancing policy to first.

Health checks with detect when your upstream is down. The first policy routes requests to the first healthy upstream, which is normally your app, but when it’s down it’ll fallback to your maintenance container.

Can you help me to understand how to configure the file? I am not able to follow the documentation on my own at this stage.

Apologies. Just not very good at this.


FYI I could not complete this task so have found a workaround using something else. Was impossible with docker/and or documentation was not possible to follow. Am more used to nginx unfortunately which is very easy.

It’s as simple as this:

reverse_proxy lemmy-ui:1234 maintenance:8080 {
	lb_policy first
	health_uri /

Everything I said above about should be trivial to figure out from the docs. Just read the sections on load balancing and health checks.

1 Like

Thank you. I did try for 3 hours but somehow despite being able to curl the site on the same machine (curl localhost:8080) caddy could never seem to display anything other than a blank page. Unfortunately was forced to go a different route as the site could not be down longer and what I also though was a trivial change was just not working. I had stripped all sorts out the caddyfile and made it about as basic as possible at one point. Unclear what the problem was and did not make enough progress. Just an unfortunate situation.

No doubt other people can get it working based on what you would suggest.

Thank you anyway :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.