将虚拟目录映射到 apache 中的另一个 Web 服务器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/984834/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Map virtual directory to another web server in apache
提问by Nathan
Is it possible to configure Apache web server to map a directory to a path on another web server? For example, can I make requests for http://server1/resource/return http://server2/resource/. If this is possible, how do I go about setting this up?
是否可以配置 Apache Web 服务器以将目录映射到另一个 Web 服务器上的路径?例如,我可以请求http://server1/resource/返回http://server2/resource/。如果可能,我该如何设置?
回答by stevedbrown
回答by Gavin M. Roy
mod_rewrite is pretty powerful for this. You'd setup a rewrite rule for /resource/ and use a 302 redirect to send people over to server two.
mod_rewrite 为此非常强大。您将为 /resource/ 设置重写规则并使用 302 重定向将人们发送到服务器 2。
http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html
http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html
Untested example:
未经测试的例子:
<location "/">
RewriteEngine On
RewriteRule ^/resource/(.*)$ http://server2/resource/ [R]
</location>
回答by Ryan Oberoi
I think this question is for serverfault.com. Not going in detail here, but you could set this up using RewriteCond, RewriteRule directives in apache configuration.
我认为这个问题是针对 serverfault.com 的。此处不详述,但您可以使用 apache 配置中的 RewriteCond、RewriteRule 指令进行设置。
I have used both mod_proxy and mod_rewriterules to achieve similar effect.
PS: check out serverfault.com and give the sysadmin folks a try.
我已经使用这两种mod_proxy and mod_rewrite规则来达到类似的效果。PS:查看 serverfault.com 并尝试使用系统管理员。

