Reverse Proxy set up

Hello,

So I am trying to set up an umbraco 13 site in .net 8 with a reverse proxy. E.g mysite-frontend.com/path-test points to mybackendwebsite.com throught cloudflare.

I have set this up in my program.cs:

if (_config[“Proxy:SiteUrl”].Contains(“/path-test”))
{
app.Use((ctx, next) =>
{
var url = _config[“Proxy:CanonicalUrl”];
var canonical = url.StartsWith(“https://”)
? url.Substring(“https://”.Length)
: url;

    ctx.Request.Host = new HostString(canonical);
    ctx.Request.Scheme = "https";
    ctx.Request.PathBase = "/path-test";
    return next();
});
app.UsePathBase("/path-test");

}

However, this uses path-test twice. in all umbraco calls. If I remove ‘ctx.Request.PathBase = “/path-test”;’ then the calls work but no css loads on the front end. If I remove ‘app.UsePathBase(“/path-test”);’ then I cannot access umbraco but the front end works.

I have tried using this but it doesn’t seem to work with a path inside of it:

"Umbraco": {
  "CMS": {
    "WebRouting": {
      "UmbracoApplicationUrl": "http://www.mysite.com/"
    }
  }
}

Just wondering if anyone had any similar issues using a proxy. Any help would be very appreicated.

Hi Brandon,

With a reverse proxy I think you need to use forward headers.

builder.Services.Configure<ForwardedHeadersOptions>(options =>
{
    options.ForwardedHeaders = ForwardedHeaders.XForwardedProto | ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedHost;
});

 app.UseForwardedHeaders();

Hi Bo,

Thanks for this. I didn’t actually post my full configuration service but I have already added this and it still doesn’t work. Do you think the code I am using above could be interfering with it? Is their anything else you would know that would be needed to set up a proxy url

Hi,

even though the question is a bit older and you’ve probably already solved the problem for yourself, I wanted to share my solution for other people.

I currently had the same problem and the simple forward headers configuration didn’t worked. But the warning message “Unknown Proxy” in the logs helped. Apparently, the middleware does nothing if it doesn’t know the proxy.

The solution was to add the proxy to the list of known proxies, and then it worked.

services.Configure<ForwardedHeadersOptions>(options =>
{
    options.ForwardedHeaders =
        ForwardedHeaders.XForwardedFor |
        ForwardedHeaders.XForwardedHost |
        ForwardedHeaders.XForwardedProto;

    options.KnownProxies.Add(IPAddress.Parse("127.0.0.1"));
});