如何通过https将Nginx配置为dotnet服务器的代理

时间:2018-08-02 19:08:48

标签: .net docker nginx .net-core docker-compose

有一个应用程序是.net核心应用程序,我无权访问源代码,但有一个只能通过https运行的编译版本。

我有nginx配置,该配置使用https和代理来运行dotnet应用。

worker_processes 4;
events { worker_connections 1024; }
http {
   sendfile on;
   upstream app_servers {
   server dotnetapp:5000;
}
server {
    listen 8080 ssl default_server;
    ssl_certificate     /etc/nginx/ssl/server.crt;
    ssl_certificate_key /etc/nginx/ssl/server.key;
    location / {
            proxy_pass         http://app_servers;
            proxy_http_version 1.1;
            proxy_set_header   Upgrade $http_upgrade;
            proxy_set_header   Connection keep-alive;
            proxy_set_header   Host $host;
            proxy_cache_bypass $http_upgrade;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Proto $scheme;
    }
}

}

,它可以与dotnet应用一起正常运行,而无需运行docker dotnet dotnetapp.dll

但是当我们尝试在此处连接docker时

The current request was rejected because the OpenID Connect server middleware has been configured to reject HTTP requests. To permanently disable the transport security requirement, set 'OpenIdConnectServerOptions.AllowInsecureHttp' to 'true'.

dotnet应用程序的Dockerfile

FROM microsoft/dotnet:2.0-runtime WORKDIR /var/www EXPOSE 5000/tcp ENV ASPNETCORE_URLS="http://*:5000"; ENTRYPOINT ["dotnet", "dotnetapp.dll"]

nginx的Dockerfile

FROM nginx RUN apt-get update RUN apt-get install iputils-ping curl -y COPY nginx.conf /etc/nginx/nginx.conf

docker-compose.yml

version: '3' services: dotnetapp: build: docker restart: always ports: - '5000:5000' volumes: - ./dotnetapp:/var/www
nginx: build: docker-nginx restart: always volumes: - ~/Documents/ssl:/etc/nginx/ssl ports: - '8080:8080' depends_on: - dotnetapp

0 个答案:

没有答案