代码之家  ›  专栏  ›  技术社区  ›  Alex

nginx反向代理以不同的方式处理请求url

  •  0
  • Alex  · 技术社区  · 7 年前

    我们正在使用nginx在AWS presto集群前面提供一个安全层。我们为nginx presto集群注册了SSL证书。我们的领域。通用域名格式

    presto请求通过具有基本身份验证的nginx传递。 针对presto的SQL查询会向服务器发出多个顺序请求,以获取查询结果。

    我们创建了一个nginx。conf,如下所示:

    location / {
      auth_basic $auth;
      auth_basic_user_file /etc/nginx/.htpasswd;
      sub_filter_types *;
      sub_filter_once off;
      sub_filter 'http://localhost:8889/' 'https://presto.nginx-presto-cluster.our-domain.com/';
      proxy_pass http://localhost:8889/;
    }
    

    普雷斯托的回复包含一个获取结果的nextUri。sub_过滤器将这些Uri从localhost:8889重写到我们的安全域,在那里它们再次通过nginx传递。

    问题是: 第一个响应的主体看起来与预期完全一致:

    {
      "id":"20171123_104423_00092_u7hmr"
      , ... 
      ,"nextUri":"https://presto.nginx-presto-cluster.our-domain.com/v1/statement/20171123_104423_00092_u7hmr/1"
      , ...
    }
    

    然而,第二个请求看起来像:

    {
      "id":"20171123_105250_00097_u7hmr"
      , ...
      , "nextUri":"http://localhost:8889/v1/statement/20171123_105250_00097_u7hmr/2"
      , ...
    }
    

    我们本来希望重写总是以同样的方式工作。

    你能帮我们吗?

    1 回复  |  直到 7 年前
        1
  •  0
  •   Alex    7 年前

    我们通过添加

    proxy_set_header Accept-Encoding "";
    

    进入上面的配置代码段。

    原因是,如果启用此功能,流量可能会在过程中被压缩。 然后,字符串替换对压缩内容无效。

    通过不接受任何编码,我们可以阻止这种压缩。