【问题标题】:How to modify index.html file in build folder before sending it on each request with Nginx server?如何在使用 Nginx 服务器发送每个请求之前修改 build 文件夹中的 index.html 文件?
【发布时间】:2021-12-08 06:47:24
【问题描述】:

我想修改服务器中的 React 的 index.html 文件,然后根据请求将其发送到浏览器。原因是,我想根据请求 url 将开放图元标记包含在头部中。我如何使用 Nginx 服务器实现这一点?

【问题讨论】:

标签: javascript reactjs nginx facebook-opengraph server-side-rendering


【解决方案1】:

这里有几个选项。

使用 NGINX 子模块

http://nginx.org/en/docs/http/ngx_http_sub_module.html

sub_filter '<a href="http://127.0.0.1:8080/' '<a href="https://$host/';

使用 NGINX njs

http://nginx.org/en/docs/http/ngx_http_js_module.html#js_body_filter

您可以使用 njs 和 js_body_filter 过滤响应正文。就个人而言,我会使用 njs 方式,因为您可以更灵活地添加/更改数据。

确保在主 nginx.conf 文件中加载 ngx_http_js_module。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-18
    • 1970-01-01
    • 2021-12-22
    • 1970-01-01
    • 2012-11-30
    • 2015-02-07
    • 1970-01-01
    • 2013-05-30
    相关资源
    最近更新 更多