azure - ASP.NET Core Docker 容器内的 Nginx

标签 azure docker nginx asp.net-core

不幸的是,没有太多关于如何将 Nginx 或 Apache 代理注入(inject) ASP.NET Core Docker 容器的文档。 这是一份很好用的手册,但它有针对 ASP.NET Core 应用程序和 Nginx 的单独图像。

ASP.NET Core API behind the Nginx Reverse Proxy with Docker.

我想在 Azure 上托管我的 Docker 镜像,因此我需要在我的 Docker 容器中安装 Nginx。

基于这篇文章Nginx Reverse Proxy to ASP.NET Core – Same Docker Container我创建了这个配置:

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

仍然收到“服务不可用” 可能是因为我有 Azure AAD 身份验证。 有人可以推荐一些东西或提供另一种工作配置吗?

最佳答案

曾俊的评论是对的。将 nginx 与应用程序一起托管在同一个容器中是不可能或不建议的。

我最终创建了 Ingress来自 Nginx 镜像。
已安装 Helm .
由于我的 Kubernetes 集群位于 Azure 中,我使用了下一本手册:
Create an HTTPS ingress controller on Azure Kubernetes Service

关于azure - ASP.NET Core Docker 容器内的 Nginx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50735041/

相关文章:

c# - MediatR 共享 TableBatchOperation 以在不同的处理程序中进行事务保存

windows - 有没有更好的方法对 Windows 桌面应用程序进行代码签名

ruby-on-rails - dokku - 从子文件夹运行 Rails 4 应用程序

java - 自动配置 Java 以使用分配给其 Docker 容器的最大 RAM

c# - 我可以从本地 C# 应用程序列出 Azure 资源组吗?

具有串行控制台的 Fortinet 虚拟机的 Azure 运行命令?

git - 如何使用Docker在Heroku Review App中的PATH上获取GIT?

php - 在 Nginx 中通过 phpmyadmin 将 20mb SQL 文件导入 MySQL 时出现 “connection was reset”

url - 如何将 URL 映射到端口和修改后的 URL?

java - 当请求通过 servlet 重定向到 S3 存储桶时,S3 存储桶策略不起作用