Nginx 无需上游保持活动

问题描述 投票:0回答:1

我使用变量来定义我的 proxy_pass 目标,类似于 这个答案,但在我的情况下,该值是从传入请求的查询参数中提取的,因此例如/?url=http://example.com 将被代理到 example.com。由于 proxy_pass 参数是一个变量,因此我的配置中没有上游指令。 代理工作正常。 然而,连接在每次请求后都会关闭,我希望它们活着来分摊 TCP 握手。 根据这些指示,这需要在上游指令中使用 keepalive 指令。 如果没有上游指令,我该如何做到这一点?

这是我的完整配置:

server {
  if ($arg_url ~ \/\/([^\/]*)) {
    set $proxy_host $1; 
  }

  if ($proxy_host = "") {
    return 404;
  }

  resolver 8.8.8.8;
  location / {
    proxy_http_version 1.1;
    proxy_set_header Connection "";   

    proxy_set_header Host $proxy_host;
    proxy_pass $arg_url;
  }
}
nginx proxypass
1个回答
0
投票

根据 https://groups.google.com/g/openresty-en/c/qmdgOTGbqtg?pli=1,如果您知道上游的可能集合,则可以定义上游,然后连接的保活池将连接到其中之一时使用。

© www.soinside.com 2019 - 2024. All rights reserved.