Browse Source

Added workaround for Nginx and Docker

master
Kenneth Bruen 2 years ago
parent
commit
0da275e039
Signed by: kbruen
GPG Key ID: C1980A470C3EE5B1
  1. 1
      Dockerfile
  2. 12
      server/Startup.cs

1
Dockerfile

@ -20,4 +20,5 @@ RUN dotnet publish -c release -o /app --no-restore
FROM mcr.microsoft.com/dotnet/aspnet:6.0 FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /app WORKDIR /app
COPY --from=build /app ./ COPY --from=build /app ./
ENV INSIDE_DOCKER=true
ENTRYPOINT ["dotnet", "Server.dll"] ENTRYPOINT ["dotnet", "Server.dll"]

12
server/Startup.cs

@ -1,6 +1,9 @@
using System;
using System.Net;
using System.Text.Json; using System.Text.Json;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
@ -18,6 +21,11 @@ namespace Server {
// This method gets called by the runtime. Use this method to add services to the container. // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) { public void ConfigureServices(IServiceCollection services) {
if ((Environment.GetEnvironmentVariable("INSIDE_DOCKER") ?? "").Length > 0) {
services.Configure<ForwardedHeadersOptions>(options => {
options.KnownProxies.Add(Dns.GetHostAddresses("host.docker.internal")[0]);
});
}
services.AddSingleton<IDataManager, DataManager>(); services.AddSingleton<IDataManager, DataManager>();
services.AddSingleton<IDatabase, Database>(); services.AddSingleton<IDatabase, Database>();
services.AddSingleton<NodaTime.IDateTimeZoneProvider>(NodaTime.DateTimeZoneProviders.Tzdb); services.AddSingleton<NodaTime.IDateTimeZoneProvider>(NodaTime.DateTimeZoneProviders.Tzdb);
@ -34,6 +42,10 @@ namespace Server {
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
app.UseForwardedHeaders(new ForwardedHeadersOptions {
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto,
});
if (env.IsDevelopment()) { if (env.IsDevelopment()) {
app.UseDeveloperExceptionPage(); app.UseDeveloperExceptionPage();
app.UseSwagger(); app.UseSwagger();

Loading…
Cancel
Save