简体   繁体   English

Apache反向代理:(保持现有路由有效)

[英]Apache Reverse Proxy: (Keeping Existing route alive)

I have an app running on localhost:3000 . 我有一个在localhost:3000上运行的应用程序。 I also have another app that is configured to run on virtualhost local.testserver.com 我还有另一个配置为在virtualhost local.testserver.com上运行的应用程序

I want to create an apache reverse proxy that will route all request from local.testserver.com/finance to my app that runs at localhost:3000 . 我想创建一个Apache反向代理,它将所有请求从local.testserver.com/finance路由到运行在localhost:3000的应用程序。 At the same time, I want to be able to access my app when I go to localhost:3000 . 同时,当我转到localhost:3000时,我希望能够访问我的应用程序。

Below is the configuration I am using currently. 以下是我当前使用的配置。 This works for routing request from local.testserver.com/finance to my localhost:3000 app. 这适用于将请求从local.testserver.com/finance路由到我的localhost:3000应用程序。 But whenever I visit localhost:3000 directly it redirects me back to local.testserver.com 但是,每当我直接访问localhost:3000时 ,它就会将我重定向回local.testserver.com

<Location /finance >
    ProxyPass http://localhost:3000
    ProxyPassReverse http://localhost:3000
</Location>

You will need to add the path on the ProxyPassReverse setting to "/finance" so it knows where to reverse requests back. 您将需要在ProxyPassReverse设置上将路径添加到“ / finance”,以便它知道在哪里将请求回退。

You may not need the <Location /finance>...</Location> part 您可能不需要<Location /finance>...</Location>部分

ProxyPass "/finance" http://localhost:3000
ProxyPassReverse "/finance" "http://localhost:3000"

Please refer to the documentation to better understand how ProxyPassReverse works here: 请参考文档以更好地了解ProxyPassReverse的工作原理:

https://httpd.apache.org/docs/2.4/mod/mod_proxy.html#proxypassreverse https://httpd.apache.org/docs/2.4/mod/mod_proxy.html#proxypassreverse

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM