Method and rewrite dont work inside reverse_proxy?

1. Caddy version (caddy version):


2. How I run Caddy:

a. System environment:

Docker, Kubernetes

b. Command:

caddy run -config /etc/caddy/Caddyfile

c. Service/unit/compose file:

d. My complete Caddyfile or JSON config:

    auto_https off
    admin off

:9080 {
    route /authtest {
        reverse_proxy http://localhost:8095 {
            # Always GET, so that the incoming
            # request's body is not consumed
            method GET

            # Change the URI to the auth gateway's
            # verification endpoint
            rewrite /ping

            # Forward the original method and URI,
            # since they get rewritten above; this
            # is in addition to other X-Forwarded-*
            # headers already set by reverse_proxy
            header_up X-Forwarded-Method {method}
            header_up X-Forwarded-Uri {uri}

            # On a successful response, copy response headers
            @good status 2xx
            handle_response @good {
                request_header {
                    # for example, for each copy_headers field...
                    Remote-User {rp.header.Remote-User}
                    Remote-Email {rp.header.Remote-Email}

3. The problem I’m having:

I need to call an authentication service before I grant access to a certain url.
For this I tried the code which you can get from the forward_auth directive documentation.
The problem is that I can’t use the method or rewrite directive inside reverse_proxy altough it is listed in the syntax section for the reverse_proxy directive.

Do I have a logic/syntax error or why does my caddyfile not work ?
Thank you !

4. Error messages and/or full log output:

{"level":"info","ts":1658833923.533105,"msg":"using provided configuration","config_file":"/etc/caddy/Caddyfile","config_adapter":"caddyfile"}
run: adapting config using caddyfile: parsing caddyfile tokens for 'route': /etc/caddy/Caddyfile:35 - Error during parsing: parsing caddyfile tokens for 'reverse_proxy': /etc/caddy/Caddyfile:12 - Error during parsing: unrecognized subdirective method

5. What I already tried:

Tried to google my problem.

6. Links to relevant resources:

forward_auth (Caddyfile directive) — Caddy Documentation.
reverse_proxy (Caddyfile directive) — Caddy Documentation

You’re using too old a version.

Those features were added in v2.5.1. Please upgrade to the latest, v2.5.2.

1 Like

Thanks for your reply. I will try it with v2.5.1. Another version is currently not possible in my working environment ^^

v2.5.1 has bugs, you really should use v2.5.2.

1 Like

I would like to use v2.5.2 but v2.5.1 is the only available version atm because it is integrated in a third party software we use :confused:

Then I suggest you reach out to the authors of that software to provide an update.

1 Like

What is the 3rd party software you’re using?

It´s really only usable in our customers ecosystem and therefore not known in the general public ^^ But it got updated today with the right version. Thanks for your help!

1 Like

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