|
16 | 16 | using BLite.Server.Telemetry; |
17 | 17 | using BLite.Server.Transactions; |
18 | 18 | using Microsoft.AspNetCore.Authentication; |
| 19 | +using Microsoft.AspNetCore.HttpOverrides; |
19 | 20 | using Microsoft.OpenApi; |
20 | 21 | using OpenTelemetry.Metrics; |
21 | 22 | using OpenTelemetry.Resources; |
@@ -227,6 +228,12 @@ static string ResolveAppPath(string path) => |
227 | 228 |
|
228 | 229 | var restHostFilter = HostFilter(app.Configuration["Kestrel:Endpoints:Rest:Url"]); |
229 | 230 | var studioHostFilter = HostFilter(app.Configuration["Kestrel:Endpoints:Studio:Url"]); |
| 231 | +// If Studio is accessed via a reverse proxy, the Host header will be the proxy |
| 232 | +// domain (e.g. studio.example.com) rather than *:2628. Studio:Host overrides |
| 233 | +// the port-based filter so RequireHost() matches the proxied hostname instead. |
| 234 | +var studioHostOverride = app.Configuration.GetValue<string>("Studio:Host"); |
| 235 | +if (!string.IsNullOrWhiteSpace(studioHostOverride)) |
| 236 | + studioHostFilter = studioHostOverride; |
230 | 237 | // Apply filters only when the two endpoints have actually different ports. |
231 | 238 | bool portsAreSeparate = restHostFilter is not null |
232 | 239 | && studioHostFilter is not null |
@@ -263,6 +270,15 @@ static string ResolveAppPath(string path) => |
263 | 270 | if (app.Environment.IsDevelopment()) |
264 | 271 | app.MapGrpcReflectionService(); |
265 | 272 |
|
| 273 | +// Forward headers from reverse proxy (X-Forwarded-For, X-Forwarded-Proto, X-Forwarded-Host). |
| 274 | +// Required for correct host matching (RequireHost) and HTTPS detection when behind nginx/Plesk. |
| 275 | +app.UseForwardedHeaders(new ForwardedHeadersOptions |
| 276 | +{ |
| 277 | + ForwardedHeaders = ForwardedHeaders.XForwardedFor |
| 278 | + | ForwardedHeaders.XForwardedProto |
| 279 | + | ForwardedHeaders.XForwardedHost |
| 280 | +}); |
| 281 | + |
266 | 282 | // Static files — must precede endpoint mapping (only needed for Studio CSS/JS) |
267 | 283 | if (studioEnabled) |
268 | 284 | app.UseStaticFiles(); |
|
0 commit comments