我正在尝试在Apache中设置反向代理来提供React / Redux / webpack包 . 我有一个Express服务器文件服务我的静态文件和index.html,如下所示:

const express = require('express');
const path = require('path');

const app = express();
const port = process.env.PORT || 3000;

app.use(express.static('./dist'));
app.get('/', (req, res) => {
  res.sendFile(path.join(__dirname, 'dist', 'index.html'));
});

app.listen(port, () => {
  console.log(`Server running on port ${port}`);
});

我的apache配置看起来像这样:

<VirtualHost *:80>
  ProxyRequests off
  ProxyPass "/foo/" "http://localhost:8777/"
  ProxyPassReverse "/foo/" "http://localhost:8777/"
</VirtualHost>

现在,当导航到example.com/foo时,我的index.html和webpack包正确提供,但是React路由器抛出一个错误,说 /foo/ 与任何路由都不匹配 . 显然,这是因为 /foo 是该应用程序的代理位置,并且路由器反应路由器不会(也不应该)考虑 生产环境 中使用的代理路径 .

如何设置Apache以便在将请求发送到 localhost:8777 时,apache不会传递 /foo 路径?换句话说,如何设置proxypass以便将对 example.com/foo/bar 的请求转换为服务器上的 localhost:8777/bar 请求,然后返回到客户端,就像它来自example.com/foo/bar一样?