首页 > 解决方案 > 通过 Apache 反向代理访问 React 开发环境

问题描述

我只是想开始使用基本的 create-react-app。我可以通过典型的 localhost:3000 访问开发环境,但我想通过我的公共 apache 服务器访问它。我已经通过反向代理在子目录中进行了设置:

<VirtualHost *:80>
    ServerName example.com
    ProxyPass /react-app http://127.0.0.1:3000/
    ProxyPassReverse /react-app http://127.0.0.1:3000/
</VirtualHost>

这可行,除了 index.html 中的引用被编码为仅从根目录查看。例如 js 包位于:

<script type="text/javascript" src="/static/js/bundle.js">

当它的实际位置真的下/react-app/static/js/bundle.js。或者,这也可以制成相对 URI。

我的几个问题:

标签: reactjsapachereact-router

解决方案


推荐阅读