[英]React app fails to run with Apache reverse proxy
I'm using the reverse-proxy
apache2 module to forward any request from https://my_server.com/test_app/
to the react production app, which is running on :3000
.我正在使用
reverse-proxy
apache2 模块将来自https://my_server.com/test_app/
的任何请求转发到在:3000
上运行的反应生产应用程序。
If i'm using https://my_server.com:3000
, everything works fine.如果我使用
https://my_server.com:3000
,一切正常。 But https://my_server.com/test_app/
fails then to get the static files and react fails to load.但是
https://my_server.com/test_app/
然后无法获取 static 文件并且反应无法加载。 It seems to request the static files on the port 80, but my react app is running on 3000.它似乎在端口 80 上请求 static 文件,但我的反应应用程序在 3000 上运行。
How can i fix this?我怎样才能解决这个问题?
package.json package.json
{
"private": true,
"homepage": "/",
...
}
httpd.conf httpd.conf
ProxyPass /test_app http://localhost:3000
Instead of using serve
, i just placed the contents of the build into a directory in /var/www/html/<Some-Directory>
(So i'm using Apache only).我没有使用
serve
,而是将构建的内容放入/var/www/html/<Some-Directory>
中(所以我只使用 Apache )。 I had to define basename
for the <Router />
and update my links, but seems to work fine for now.我必须为
<Router />
定义basename
并更新我的链接,但现在似乎工作正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.