[YARP] How to set up a reverse proxy for another full web server in a sub path? #2604
-
I have a Qliksense server on some domain and I have its certificate (pfx) and I want to make a reverse proxy to it with ASP.NET + YARP so I need a dynamic way to make all of the QlikSense paths be of sub path I heard about something in the transformation like:
but it gives me error, not sure if I'm using it correctly |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The backend server has to cooperate with a reverse proxy. For example, it should use relative paths in hrefs/redirects, or it should generate those paths by honoring headers like If the backend service isn't cooperative / you can't control it, you then have to fix up any such responses. builder.Services.AddReverseProxy()
.LoadFromConfig(builder.Configuration.GetSection("ReverseProxy"))
.AddTransforms(context =>
{
if (context.Route.RouteId == "myQlikRoute")
{
context.AddResponseTransform(context =>
{
if (context.ProxyResponse.Headers.Location is { } location)
{
context.HttpContext.Response.Headers[HeaderNames.Location] = "...";
}
return ValueTask.CompletedTask;
});
}
}); |
Beta Was this translation helpful? Give feedback.
The backend server has to cooperate with a reverse proxy. For example, it should use relative paths in hrefs/redirects, or it should generate those paths by honoring headers like
"X-Forwarded-Prefix"
.If the backend service isn't cooperative / you can't control it, you then have to fix up any such responses.
The configuration file transforms don't currently support the sort of syntax you tried to use to generate dynamic header values.
You could achieve this sort of transformation from code though, e.g. something like