I'm trying to run Blazor WASM app on NGINX inside Docker Container on https. When I type https://localhost:8021 in browser (8021 is mapped from port 443), the site correctly loads. I also want to redirect from http://localhost:8020 (8020 is mapped from port 80) to previous https address. But no matter how I configure my nginx.conf, the redirect goes to completely weird URL https://2f81239fe704/. Can anyone see what am I doing wrong here?
nginx.conf
events { }
http {
include mime.types;
server {
listen 80;
listen 443 ssl;
server_name _;
if ($scheme = http) {
return 301 https://$host$request_uri;
# except $host I also tried localhost:8021/443, 127.0.0.1:8021:443,
# host.docker.internal:8021/443, nothing seems to work
}
ssl_certificate /https/localhost.crt;
ssl_certificate_key /https/localhost.rsa;
location / {
root /usr/share/nginx/html;
try_files $uri $uri/ /index.html =404;
}
}
}
Dockerfile:
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
# COPY FILES OMITTED
RUN dotnet restore "Solution.sln"
COPY . .
WORKDIR "src/Admin/"
RUN dotnet build "Admin.csproj" -c Debug -o /app/build
FROM build AS publish
RUN dotnet publish Admin.csproj -c Debug -o /app/publish
FROM nginx:alpine AS final
EXPOSE 80
EXPOSE 443
WORKDIR /usr/share/nginx/html
COPY --from=publish /app/publish/wwwroot .
COPY src/Admin/nginx.conf /etc/nginx/nginx.conf
docker-compose.yml
admin:
image: admin
build:
context: .
dockerfile: src/Admin/Dockerfile
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=https://+;http://+
ports:
- "8020:80"
- "8021:443"
volumes:
- ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro
- ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro
- ~/.aspnet/https:/https:ro