nginx proxy_pass不通过uri

时间:2019-01-14 16:22:23

标签: nginx webserver proxypass ssi

我的目标是,domain.com/do/that/的调用将包含页面otherdomain.com/for/that/,并用ssi&subs过滤器替换该内容的一部分。 同样,重要的是,如果有人致电domain.com/do/that/for-me,则包含的页面将只请求otherdomain.com/for/that,而 otherdomain.com/for/that/for-me

我目前已对此进行设置:

location ^~/do/that/ {
  proxy_pass http://otherdomain.com/do/that/;

  ssi on;
  subs_filter_types text/html;

  set $includeUri "";
  if ( $uri != "/do/that/" ){
    set $includeUri "$uri-parts";
  }

 subs_filter '<div class="rpl-container">' '<div class="rpl-container"><!--# include virtual="/my-ssi-include/$includeUri" -->' ir;
}

实现uri的“忽略”的方式是什么?

1 个答案:

答案 0 :(得分:0)

已经找到解决方案:

我只是将var与静态网址一起使用,并将其设置为proxy_pass

location ^~/do/that/ {
  set $staticUrl 'http://otherdomain.com/do/that/';
  proxy_pass $staticUrl;

  ssi on;
  subs_filter_types text/html;

  if ($uri ~* "/do/that/(.*\.html)"){
    set $includeUri "$1";
  }

 subs_filter '<div class="rpl-container">' '<div class="rpl-container"><!--# include virtual="/my-ssi-include/$includeUri" -->' ir;
}