Unfortunately there is not much documentation about how is it possible to inject Nginx or Apache proxy into ASP.NET Core Docker container. Here is nice manual that works, but it has separate images for ASP.NET Core application and Nginx.
ASP.NET Core API behind the Nginx Reverse Proxy with Docker.
I want to host my Docker image on Azure, so I need to have Nginx inside my Docker container.
Based on this article Nginx Reverse Proxy to ASP.NET Core – Same Docker Container I have created this configuration:
nginx.conf
worker_processes 4;
events { worker_connections 1024; }
http {
sendfile on;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
large_client_header_buffers 4 16k;
upstream app_servers {
server 127.0.0.1:5000;
}
server {
listen 80;
location / {
proxy_pass http://app_servers;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
}
}
}
Dockerfile
FROM microsoft/aspnetcore:2.0 AS base
WORKDIR /app
EXPOSE 80
FROM microsoft/aspnetcore-build:2.0 AS build
RUN apt-get update
RUN apt-get install -y apt-utils
RUN apt-get update
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y nginx
WORKDIR /src
COPY MyApp.csproj MyApp.csproj
RUN dotnet restore
COPY . .
WORKDIR /src
RUN dotnet build -c Release -o /app
FROM build AS publish
RUN dotnet publish -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
RUN rm -f /app/startup.sh
COPY startup.sh /app
RUN chmod 755 /app/startup.sh
RUN rm -f /etc/nginx/nginx.conf
COPY nginx.conf /etc/nginx
ENV ASPNETCORE_URLS http://+:5000
EXPOSE 5000 80
CMD ["sh", "/app/startup.sh"]
Startup.sh
#!/bin/bash
service nginx start
dotnet /app/MyApp.dll
Still receive "Service unavailable" May be because I have Azure AAD authentication. Can someone recommend something or provide another working configuration?
Tseng Jun was right in comments. Hosting nginx together with application in same container is not possible or not recommended.
I have ended up with creating Ingress from Nginx image.
Has installed it with Helm .
As my Kubernetes cluster was in Azure I have used next one manual:
Create an HTTPS ingress controller on Azure Kubernetes Service
I have some Azure Linux WebApps using docker-compose to serve Asp.Net Core 3.1 Apps with Nginx as a reverse proxy (they also have WebJobs running there). The WebApps have public repositories at GitHub, Docker registry and Azure Pipelines.
https://pdf.ricardogaefke.com/
https://webjobs.ricardogaefke.com/
You can check for public repos at How it works
pages.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.