设置 Apache 虚拟主机和 ProxyPass
我正在尝试在 WAMPSERVER 2.0i 安装上设置虚拟主机。目前看起来是这样的:
http://domain/main
http://domain/sub1
http://domain/sub2
我需要进行设置,以便 1) 访问 http://domain/ 将重定向到 http://domain/main,但 2) http://domain/sub1 和 http://domain/sub2 保持原样工作。
当我尝试像这样使用 ReverseProxy 时,
<VirtualHost *:80>
DocumentRoot "D:/WAMP/www"
ServerName domain
ProxyPass / http://domain/main/
ProxyPassReverse / http://domain/main/
ErrorLog "logs/error.log"
CustomLog "logs/access.log" common
</VirtualHost>
它对于第一个选项效果很好。但是,尝试访问 http://domain/sub1 或 http://domain/sub2 给我“从远程服务器读取错误”...
我尝试添加类似的内容
ProxyPass /sub1/ http://domain/sub1/
ProxyPassReverse /sub1/ http://domain/sub1/
但没有任何运气。
任何人都可以对此提供任何建议吗?谢谢!
I am trying to set up Virtual Hosts on my WAMPSERVER 2.0i installation. Currently it looks like that:
http://domain/main
http://domain/sub1
http://domain/sub2
I need to set it up so that 1) accessing http://domain/ would redirect to http://domain/main, but 2) http://domain/sub1 and http://domain/sub2 remain working as they are.
When I'm trying to use ReverseProxy like this
<VirtualHost *:80>
DocumentRoot "D:/WAMP/www"
ServerName domain
ProxyPass / http://domain/main/
ProxyPassReverse / http://domain/main/
ErrorLog "logs/error.log"
CustomLog "logs/access.log" common
</VirtualHost>
it works fine for the first option. However, trying to access http://domain/sub1 or http://domain/sub2 gives me "Error reading from remote server"...
I tried to add something like
ProxyPass /sub1/ http://domain/sub1/
ProxyPassReverse /sub1/ http://domain/sub1/
But without any luck.
Can anyone give any advice about this? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来您可能需要为 sub1 和 sub2 指定别名(和位置/目录)指令。
更一般地说,由于您似乎正在从同一域运行所有内容,因此您可能应该使用 mod_rewrite,而不是代理。
It sounds like you may need to specify Alias (and Location/Directory) directives for sub1 and sub2.
More generally, since you seem to be running everything from the same domain, it's probably mod_rewrite you should use, not proxy.
以更简单的方式解决。由于我不关心用户访问 http://domain/ 时可以看到的地址行,所以我只使用了一个简单的
重定向匹配
。Solved in a much easier way. Since I don't care about address line which users can see when they access http://domain/, I used just a simple
RedirectMatch
.