【问题标题】:nginx sub_filter module not working with REACT websitesnginx sub_filter 模块不适用于 REACT 网站
【发布时间】:2022-04-08 18:08:09
【问题描述】:

我正在尝试如下所示的 nginx 子过滤器模块。我正在将流量路由到 reactjs.org 并使用 nginx sub_filter 模块进行动态文本替换。下面的 nginx 配置不适用于任何基于反应的网站,我将文本“反应”更改为“测试”。我该如何克服这个问题?

location / {
    proxy_pass https://reactjs.org;
    sub_filter '<h1 class="css-159p4b7">React</h1>' '<h1 class="css-159p4b7">Test</h1>';
    sub_filter_once off;
}

【问题讨论】:

  • 原因是响应(您可以在 Chrome 等浏览器的 DevTools 中检查)发送回 text/html 内容,该内容会加载修改 DOM 并显示您所看到内容的脚本作为 React 页面。

标签: reactjs nginx nginx-reverse-proxy nginx-config


【解决方案1】:

当我遇到同样的问题时,Google 将我带到了这个页面,所以我认为分享答案很重要。

tl;dr 我将以下配置添加到我的 nginx 配置文件中的位置:

proxy_set_header Accept-Encoding "";

它为什么起作用的解释在这里:https://stackoverflow.com/a/36274259

我希望这会有所帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-30
    • 1970-01-01
    • 2019-12-13
    • 2013-01-27
    • 2023-03-24
    相关资源
    最近更新 更多