![](/img/trans.png)
[英]Error when connecting to Azure SQL Server from an ASP.Net Core App (Blazor) inside a Docker container
[英]Nginx inside ASP.NET Core Docker container
不幸的是,關於如何將 Nginx 或 Apache 代理注入 ASP.NET Core Docker 容器的文檔並不多。 這是一個很好用的手冊,但它為 ASP.NET Core 應用程序和 Nginx 提供了單獨的圖像。
帶有 Docker 的 Nginx 反向代理背后的 ASP.NET Core API。
我想在 Azure 上托管我的 Docker 映像,所以我需要在我的 Docker 容器中安裝 Nginx。
基於這篇文章Nginx Reverse Proxy to ASP.NET Core – Same Docker Container我創建了這個配置:
配置文件
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;
}
}
}
文件
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"]
啟動文件
#!/bin/bash
service nginx start
dotnet /app/MyApp.dll
仍然收到“服務不可用”可能是因為我有 Azure AAD 身份驗證。 有人可以推薦一些東西或提供另一種工作配置嗎?
曾俊的評論是對的。 不可能或不建議將 nginx 與應用程序一起托管在同一容器中。
我最終從 Nginx 圖像創建了Ingress 。
已使用Helm安裝它。
由於我的 Kubernetes 集群在 Azure 中,我使用了下一本手冊:
在 Azure Kubernetes 服務上創建 HTTPS 入口控制器
我有一些 Azure Linux WebApps 使用 docker-compose 為 Asp.Net Core 3.1 應用程序提供服務,Nginx 作為反向代理(它們也有 WebJobs 在那里運行)。 WebApps 在 GitHub、Docker 注冊表和 Azure Pipelines 上有公共存儲庫。
https://pdf.ricardogaefke.com/
https://webjobs.ricardogaefke.com/
您可以在How it works
頁面檢查公共存儲庫。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.