菜鸟求助,nginx 反代 https://AAA.com 页面打开为空,如果直接反代 http://AAA.com 则完全正常; 看错误代码
[error] 5790#5790: *15933 upstream prematurely closed connection while reading upstream, client: 127.0.0.1, server: m.shss.pw, request: "GET /bbs/index.php HTTP/2.0", upstream: "https://数字 IP:443/bbs/index.php", host: "BBB.com", referrer: "https:/BBB.com/"
https://AAA.com 是 ke 可以打开的,但是 https://数字 IP:443/ 显然是无法打开的,所以报错
请问这种情形下 nginx 如何修改配置?
1 mxT52CRuqR6o5 2022-09-01 23:04:10 +08:00 via Android host 对的就没问题,host 是 http 协议的 header ,upstream 不是,问题原因应该不是你目前认为的那样 |
![]() | 2 turan12 2022-09-01 23:05:00 +08:00 via iPhone 把 conf 文件贴上来看看 |
![]() | 3 liuyinltemp OP 反代源站 http 是没问题的,ip 也是源站的 ip ,https://数字 IP:443 这个是没法访问 |
![]() | 4 liuyinltemp OP server { listen 443 ssl http2; server_name BBB.com; ssl_certificate cert/XXX.crt; ssl_certificate_key cert/XXX.key; resolver 8.8.8.8 1.1.1.1 valid=3600s; resolver_timeout 3s; set $backend https://AAA.com; add_header Strict-Transport-Security "max-age=31536000;includeSubDomains" always; add_header X-Frame-Options SAMEORIGIN; add_header Referrer-Policy same-origin; add_header X-Content-Type-Options nosniff; proxy_set_header Early-Data $ssl_early_data; location / { proxy_redirect off; proxy_pass $backend; proxy_ssl_server_name on; proxy_http_version 1.1; proxy_set_header Connection ""; proxy_set_header Host AAA.com; proxy_set_header Accept-Encoding ""; proxy_set_header X-Real-IP $remote_addr; prxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Referer https://AAA.com; } } |
5 nulIptr 2022-09-01 23:11:05 +08:00 代理 https 需要配证书啊。。。不然不就是中间人了吗 |
![]() | 6 liuyinltemp OP |
![]() | 7 liuyinltemp OP 为啥 upstream 哪儿用 ip 替换了域名 |
8 hefish 2022-09-01 23:22:40 +08:00 日志里面是 HTTP/2.0 , 配置里面是 1.1 ,不知道有没有关系。 |
9 nulIptr 2022-09-01 23:24:03 +08:00 @liuyinltemp #6 我这样解释一下, 证书是颁发给域名的,你的 a 域名有 a 证书,而 a 证书用不到 b 域名上。如果 a 服务只有 a 域名的 https 的话是不能被 b 域名代理的,如果是同一个域名不同服务器的话理论上可以代理,具体怎么配就不知道了 你这问题把我给问懵逼了,实际我一般只在最外面的 ingress 网关配 https ,内部的微服务都是 http 。 |
10 PMR 2022-09-01 23:34:55 +08:00 在什么地方看过 proxy_pass 是固死 IP 的 开启 SNI 程序启动时 会自动解析 IP 并固定 域名的解析变动 要 reload nginx 才能 proxy_pass 到变动 IP 找下 nginx plus 的 example 照葫芦画瓢就行 |
![]() | 11 ab 2022-09-02 00:26:02 +08:00 via iPhone 用 stream 转发会更方便 |
![]() | 12 ZE3kr 2022-09-02 00:26:32 +08:00 via iPhone |
![]() | 13 ZE3kr 2022-09-02 00:27:40 +08:00 via iPhone proxy_ssl_name V2EX 回复不能编辑,没办法,需要你自己拼凑下 |
![]() | 14 liuyinltemp OP up 一下,这个配置反代其他 https 域名没有问题 |
![]() | 15 liuyinltemp OP 对了,还有一个特征,就是访问 https://AAA.com 是正常的,但是跳转 https://AAA.com/bbs/index.php 出现问题,只显示网页底色 |
16 konsh 2022-09-02 10:42:56 +08:00 @liuyinltemp https 协议是需要 ca 证书,证书是颁发给域名的,与 IP 无关,所以访问 https://XXX.com 是没有问题的,而 https://ip:443 则是无法访问的。看了下你的 conf 文件,proxy_pass 代理的是 https 请求,加上证书配置试试看,参考文档 https://docs.nginx.com/nginx/admin-guide/security-controls/securing-http-traffic-upstream/ |
17 jiabing520a 2022-09-02 13:28:37 +08:00 我是在 /etc/hosts 里指定源站 IP ,使用起来没有问题 |
![]() | 18 liuyinltemp OP chrome F12 查看显示 Failed to load resource: net::ERR_HTTP2_PROTOCOL_ERROR |
![]() | 19 liuyinltemp OP @konsh 没有源站的证书 |
![]() | 20 liuyinltemp OP 单独看反代后 js 是可以正常打开,现在就是进入 https://AAA.com/bbs/index.php 没有响应 |
![]() | 21 liuyinltemp OP curl: (60) SSL certificate problem: unable to get local issuer certificate More details here: https://curl.se/docs/sslcerts.html curl failed to verify the legitimacy of the server and therefore could not establish a secure connection to it. To learn more about this situation and how to fix it, please visit the web page mentioned above. |
![]() | 22 liuyinltemp OP 又查了一下,应该是 vps 下访问源站有问题,但是证书又是对的。 |
![]() | 23 liuyinltemp OP 应该是源站的证书缺失了中间证书,这种情况有啥办法 |
![]() | 24 liuyinltemp OP 源站补齐中间证书就好了 |