【问题标题】:Two upstreams, one http, the other https两个上游,一个 http,另一个 https
【发布时间】:2021-02-10 19:55:22
【问题描述】:

大家好! 我在设置openresty时遇到了一个问题,请帮忙。 我有什么:openresty + lua。 Openresty 配置:

upstream a {
   server 1.1.8.1:4707;
}

upstream c {
   server 1.1.8.1:4707;
}
server {
location / {
   proxy_set_header X-Forwarded-Host $host;
   proxy_set_header X-Forwarded-Server $host;
   proxy_set_header X-Real-IP $remote_addr;
   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
   proxy_set_header X-Url-Scheme $scheme;
   proxy_set_header X-Forwarded-Proto $scheme;
   proxy_set_header Host $http_host;
   proxy_redirect off;
   proxy_ssl_verify off;
   if ($request_method = POST ) {
   set $upstream '';
   access_by_lua '
   ngx.req.read_body()
   local  match0 = ngx.re.match(ngx.var.request_body, "aaa.*")
   local  match1 = ngx.re.match(ngx.var.request_body, "bbb.*")
   if match0 then
      ngx.var.upstream = "a"
   else
      ngx.var.upstream = "c"
   end
   ';
   proxy_pass http://$upstream;
   }
}
}

目标:根据传递的请求方法将请求分发到上游。请求以 json-rpc 格式发送。 问题:我有两个上游。一个上游可通过 http 协议获得,另一个可通过 https 获得,我没有遇到的问题如下,一次只有 1 个上游工作。 即使您创建单独的类似配置,也只有 1 个可用且 1 个可以工作。 如果有人遇到,请帮忙。 如何指定可通过不同协议使用的多个上游?或者我没有正确注册配置? 即使在 openresty 设置中指定的指令“proxy_ssl_verify off”也无济于事 提前致谢。

【问题讨论】:

    标签: nginx lua openresty


    【解决方案1】:

    在这里查看我的答案https://stackoverflow.com/a/64331014/2060502

    您可以使用不同的上游和 proxy_* 指令配置 2 个内部位置,并通过 ngx.exec() Lua API 进行内部重定向,最好是在 rewrite_by_lua_block 的上下文中

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-23
      • 2019-04-12
      • 2018-09-17
      • 2013-01-05
      • 2019-01-11
      • 2015-12-02
      • 2014-04-22
      相关资源
      最近更新 更多