使用docker,我正在尝试设置一个本地反向代理,其中包括以下内容:
- 以http模式监听(我这里不需要加密)
- 将请求重定向到https服务器
这是为了缓存对openai的昂贵请求的目的。
我使用以下配置:
events { worker_connections 10;}http { proxy_cache_path /server_cache levels=1:2 keys_zone=my_cache:10m max_size=1g inactive=60m use_temp_path=off; server { listen 80; location /v1/chat/completions { proxy_pass https://api.openai.com; proxy_cache my_cache; proxy_cache_methods POST; proxy_cache_key "$request_method$request_uri$request_body"; proxy_cache_valid 200 60m; proxy_cache_valid 404 1m; proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504; proxy_cache_background_update on; proxy_cache_lock on; proxy_set_header Host $host; } location / { proxy_pass https://api.openai.com; proxy_set_header Host $host; } }}
然而,每当它处理请求时,我从nginx日志中得到这个错误:
[error] 24#24: *1 SSL_do_handshake() failed (SSL: error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure:SSL alert number 40) while SSL handshaking to upstream
我读到我需要添加一些proxy_ssl_*指令并包含一些私钥…
但为什么当我设置的服务器是http而不是https时,我必须这样做呢?而且当我直接连接到上游https服务器时,我从不需要指定任何类型的证书(更不用说私钥了,这没有意义)。
有什么解决方案吗?这是nginx的缺陷吗?
回答:
有人提到添加
proxy_ssl_server_name on;
在你的location块中。你试过这个吗?
否则,如果你想将http代理到https,我听说人们通常建议使用haproxy代替。