Deploying behind a reverse proxy
When a Lagoon application is deployed behind a reverse proxy or a gateway, HTTP header forwarding must be enabled.
Enabling HTTP header forwarding
Add the following configuration to appsettings.json:
{
"Lagoon": {
"UseForwardedHeaders": true
}
}
The UseForwardedHeaders middleware is automatically added by Lagoon with the ForwardedHeaders.All option.
For more information, see the Microsoft documentation:
- https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.builder.forwardedheadersextensions.useforwardedheaders?view=aspnetcore-8.0
- https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.httpoverrides.forwardedheaders?view=aspnetcore-8.0
- https://learn.microsoft.com/fr-fr/aspnet/core/host-and-deploy/proxy-load-balancer?view=aspnetcore-8.0
The OnConfigureForwardedHeaders method lets you customize header forwarding.
"OpenID Connect request cannot be retrieved" error
If GET /connect/authorize returns the The OpenID Connect request cannot be retrieved exception, it is probably because the HTTP request's host name does not match the PublicUrl defined in appsettings.json.
Check that:
- the URL set as
PublicUrlis correct; - the
UseForwardedHeadersoption is set totruein the configuration file.
Azure Application Gateway
Azure Application Gateway does not send the X-Forwarded-Host header, but the X-Original-Host header instead.
The application configuration must be updated by adding the following method to the Main.cs file of the Server project:
///<inheritdoc/>
protected override void OnConfigureForwardedHeaders(ForwardedHeadersOptions options)
{
base.OnConfigureForwardedHeaders(options);
options.ForwardedHostHeaderName = "X-Original-Host";
}
For more flexibility, the value can be read from the configuration.