How to configure Caddy reverse proxy for Flower with desired URL format?

I’m trying to configure Caddy as a reverse proxy for Flower, but I’m encountering an issue with the URL format. My desired Flower URL is https://dev.api.domain.com/flower/, but the current URL format is https://dev.api.domain.com/flower/flower/. How can I adjust my Caddy configuration to achieve the desired URL format?

This is my Supervisor configuration for Flower:

[program:project_flower]
command=/home/ubuntu/backend/project/venv/bin/celery -A project flower --url_prefix=/flower
directory=/home/ubuntu/backend/project/project
user=ubuntu
autostart=true
autorestart=true
redirect_stderr=true
stderr_logfile=/var/log/supervisor/project/flower_error.log
stdout_logfile=/var/log/supervisor/project/flower_out.log

And this is my Caddyfile:

{
    email sample@gmail.com
}

dev.api.domain.com {
    encode zstd gzip

    handle_path /static/* {
        file_server {
            root "/home/ubuntu/backend/project/project/static"
        }
    }

    handle_path /media/* {
        file_server {
            root "/home/ubuntu/backend/project/project/media"
        }
    }

    handle {
        reverse_proxy unix//home/ubuntu/backend/project/project/app.sock
    }

    handle_path /flower/* {
        reverse_proxy unix//home/ubuntu/backend/project/project/app.sock
    }
}

I believe the issue lies in my Caddy configuration, specifically in how I’m handling the /flower/* path. How can I adjust my Caddyfile to achieve the desired Flower URL format?

The handle_path directives strips the given path prefix from the request before continuing. This means if you receive a request to /flower/foo it will change it to /foo.

It looks like the upstream supports a URL prefix config option, so you probably don’t need to strip the path. So use handle instead of handle_path which won’t do any stripping.

2 Likes