nginx代理后502
直接访问 https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions正常
使用nginx代理后访问出现502
server {listen 9999;server_name 172.21.3.78;location ^~ /compatible-mode {proxy_pass https://dashscope.aliyuncs.com;}location / {proxy_pass http://172.21.3.78:9993;}}
21#21: *5 peer closed connection in SSL handshake (104: Connection reset by peer) while SSL handshaking to upstream, client: 10.10.10.1, server: 172.21.3.78, request: "POST /compatible-mode/v1/chat/completions HTTP/1.1", upstream: "https://47.93.243.29:443/compatible-mode/v1/chat/completions", host: "172.21.3.78:9999"
原因:
在请求时DNS域名进行解析,实际请求出去的是IP与端口,但对方系统是多个域名对应一个公网IP,这个公网IP下映射到了多个项目和服务,通过nginx的server_name进行区分,所以直接请求不通。
解决方法:
添加 proxy_ssl_server_name on;
server {listen 9999;server_name 172.21.3.78;location ^~ /compatible-mode {proxy_ssl_server_name on;proxy_pass https://dashscope.aliyuncs.com;}location / {proxy_pass http://172.21.3.78:9993;}}