c# - docker容器之间的HTTPS通信问题
问题描述
具体描述:通过HTTPS加载我的页面后,我正在尝试登录。在执行触发POST到Web api的操作时,出现Web浏览器(chrome)错误:此页面正在尝试从未经身份验证的源加载脚本。
背景:我在桥接网络中使用 docker 和三个容器:后端、前端和数据库。在我决定配置 HTTPS 之前,一切都还好。
前端 - Nginx 用作反向代理和 Angular 应用程序的 Web 服务器,仅配置为 HTTPS。后端 - .net core 3.0 web api,在不安全的 HTTP 5000 端口上工作,并带有标头转发。
Nginx 配置,至少我觉得这个问题很有趣:
upstream web-api {
server backend:5000;
}
server {
server_name <myDomainHere>.xx www.<myDomainHere>.xx;
root /usr/share/nginx/html;
index index.html;
location / {
root /usr/share/nginx/html;
try_files $uri $uri.html $uri/ /index.html;
}
location /api {
proxy_pass http://web-api;
proxy_redirect off;
proxy_http_version 1.1;
proxy_cache_bypass $http_upgrade;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
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-Proto $scheme;
proxy_set_header X-Forwarded-Host $server_name;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
我已经读过,要实现我的站点在 HTTPS 中工作,我必须在 nginx 容器上配置证书(已经完成),并将其设置为反向代理。我还更改了我的角度配置,因此调用了 nginx。
我的调查: 我创建了假的 GET 端点,我通过像https://mydomain.xx/api/GetEndpoint这样的浏览器到达它,它起作用了,我收到了响应。Nginx 能够识别位置规则,重写标头,并按照反向代理的预期转发 GET。看起来 nginx 仅使用 POST 请求转发有问题。
摘要: 我试图描述我的整个环境,因为也许质疑如何通过 nginx 转发 POST 是错误的问题。在这个技术堆栈中,也许还有其他方法可以为我的应用程序实现 HTTPS。
解决方案
推荐阅读
- c# - 如何将 Content-Type 标头添加到 .Net GET Web 请求?
- amazon-web-services - 尝试按日期过滤时出现 AWS Athena 查询错误
- python - 相互引用 Enum 成员
- r - 将一行中的值组合成r中的一列
- for-loop - 请改成嵌套for循环
- sql - 如何在多个连接行需要包含内容的情况下执行 SQL JOIN
- java - 何时在列表中使用 set 和 add 方法
- html - 对threejs的工作方式感到困惑
- mysql - SQL 按子字符串分组
- java - 如何优化多个相关 maven java 项目的 docker 构建?(缓存)