Reverse Proxy without redirecting

1. Caddy version (caddy version):


2. How I run Caddy:

Using Caddyfile as a reverse proxy from localhost.
reverse_proxy {
lb_policy header X-My-Header

a. System environment:

Ubuntu 20.04

b. Command:

sudo caddy start

d. My complete Caddyfile or JSON config:

reverse_proxy {
	lb_policy header X-My-Header

3. The problem I’m having:

Sorry if this is a Noob question, I have been trying to set up Caddy as reverse proxy such that any client in the network can use the proxy address that mirrors the destination without actually redirecting it. When i set it up, Caddy seem to be redirecting localhost (when testing inside the Caddy machine) to the destination. You can think of what i want to achieve as masking the real URL in Caddy.

4. Error messages and/or full log output:

Server works, but redirects to the address.

5. What I already tried:

I was thinking i should be making a local host and use srv+http://localhost:5099 on the upstream field to use it as the mirror.

6. Links to relevant resources:

Request matchers (Caddyfile) — Caddy Documentation (Should it be a POST request?)

I am sorry if the question sound dumb

With that Caddyfile, the only redirect Caddy will ever be issuing is http://localhosthttps://localhost.

That means the redirects are coming from upstream. When the upstream server issues a redirect, Caddy will simply faithfully pass it down to the client (your browser). If you’re getting sent to the actual hostname of the upstream server, it’s likely they are redirecting canonically to themselves (e.g. sending a Location: header to force the browser to navigate directly to their domain name).

There are ways to combat this - proxy header manipulation is quite doable, for example - but it can be a bit of a cat-and-mouse game, because it won’t fix the issue if the upstream also uses absolute URLs in HTML anchor links.

I don’t know what you’ve got upstream or what level of control you have over it. But the easiest way by far to go ahead is to have it stop using absolute URLs and canonical redirects.

1 Like

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