Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Caddy as reverse proxy to rewrite a http redirect url from an upstream response

I am having a backend that is not able when running behind a reverse proxy since I cannot configure a custom base URL.

For the login process the backend makes heavy use of HTTP redirects but due to the fact that is behind a reverse proxy it sends redirection URL that are not reachable by the client.

So I was wondering if there is a way to rewrite the upstream HTTP HEADER Location

If the backend responses

HTTP/1.1 301
Location: http://backend-hostname/auth/login

Caddy should rewrite the Location header to

HTTP/1.1 301
Location: http://www.my-super-site.com/service/a/auth/login

Is something like this possible?

I've that we can remove headers by declaring

header / {
    - Location
}

but it possible to replace the header and rewrite the URL?

like image 354
saw303 Avatar asked Jul 19 '18 08:07

saw303


People also ask

Is Caddy better than nginx?

Nginx will, overall, perform better than Caddy.

Is Caddy a load balancer?

Use Caddy for reverse proxy, active and passive health checks, load balancing, circuit breaking and caching. It has everything Built-in with no dependencies so it runs great in containers. Which makes it simple to install and simple to upgrade. Caddy has its own apt repos for Debian-based distributions.

What is Caddy file?

The Caddyfile is just a config adapter for Caddy. It is usually preferred when manually crafting configurations by hand, but is not as expressive, flexible, or programmable as Caddy's native JSON structure. If you are automating your Caddy configurations/deployments, you may wish to use JSON with Caddy's API.


1 Answers

I was also looking for answer for this question and unfortunately I've found this responses:

https://caddy.community/t/v2-reverse-proxy-but-upstream-server-redirects-to-nonexistent-path/8566

https://caddy.community/t/proxy-url-not-loading-site/5393/7

TLDR:

You need to use sub-domains rather than sub-paths for services that are not design for being after proxy (or at least configure base URL). :(

like image 141
poplawskidaniel Avatar answered Oct 22 '22 09:10

poplawskidaniel