简体   繁体   English

使用反向代理的命名空间URL(Apache)

[英]Namespace URL Using Reverse Proxy (Apache)

I have a bunch of identical apps that are configured to listen on the same url path. 我有一堆相同的应用程序,它们被配置为侦听相同的URL路径。 For example: 例如:

http://server:80/app

I would like to setup an Apache reverse proxy to provide namespacing to the URLs so each app will not have conflicting URLs: 我想设置一个Apache反向代理为URL提供命名空间,以便每个应用程序都不会有冲突的URL:

http://proxy:80/namespace1/app -> http://destserver1:80/app
http://proxy:80/namespace2/app -> http://destserver2:80/app

I played around with ProxyPass, ReverseProxyPass, and ProxyPreserveHost options to no avail. 我玩ProxyPass,ReverseProxyPass和ProxyPreserveHost选项都无济于事。 Specifically when the apps would send a redirect request the redirects would not preserve the namespace. 具体来说,当应用程序发送重定向请求时,重定向将不会保留名称空间。

What would a sample httpd config file look like to apply a namespacing function while acting as a reverse proxy? 用作反向代理时,示例httpd配置文件应如何应用命名空间功能?

This is my sample config (for a single server) that is not working with redirects: 这是我的示例配置(针对单个服务器),不适用于重定向:

Listen 80

<VirtualHost *:80>

ServerName 127.0.0.1:80

<Location /namespace/app/>
    ProxyPreserveHost on
    ProxyPass http://destserver:80/app/
    ProxyPassReverse http://destserver:80/app/
</Location>

#ErrorLog logs/test-log
</VirtualHost>

The problem is that http://proxy:80/namespace/app/path sends a redirect which becomes http://proxy:80/app/path/redirect/path (404) which is missing the namespace. 问题在于http://proxy:80/namespace/app/path发送重定向,该重定向变为缺少名称空间的http://proxy:80/app/path/redirect/path (404)

Thanks 谢谢

This tutorial provides the answer to my exact use case: http://www.apachetutor.org/admin/reverseproxies 本教程为我的确切用例提供了答案: http://www.apachetutor.org/admin/reverseproxies : http://www.apachetutor.org/admin/reverseproxies

I copied the important snippets below: 我复制了以下重要片段:

The fundamental configuration directive to set up a reverse proxy is 
ProxyPass. We use it to set up proxy rules for each of the application servers:


ProxyPass       /app1/  http://internal1.example.com/
ProxyPass       /app2/  http://internal2.example.com/

...

The command to enable such rewrites in the HTTP Headers is ProxyPassReverse. 
The Apache documentation suggests the form:


ProxyPassReverse /app1/ http://internal1.example.com/
ProxyPassReverse /app2/ http://internal2.example.com/
However, there is a slightly more complex alternative form that I recommend
as more robust:


<Location /app1/>
    ProxyPassReverse /
</Location>
<Location /app2/>
    ProxyPassReverse /
</Location>

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

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