设置Apache虚拟主机和ProxyPass

时间:2010-09-27 22:22:23

标签: apache wamp reverse-proxy mod-proxy

我正在尝试在我的WAMPSERVER 2.0i安装上设置虚拟主机。目前它看起来像是:

http://domain/main
http://domain/sub1
http://domain/sub2

我需要对其进行设置,以便1)访问http://domain/会重定向到http://domain/main,但是2)http://domain/sub1http://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/sub1http://domain/sub2会让我“从远程服务器读取错误”...

我尝试添加类似

的内容
ProxyPass /sub1/ http://domain/sub1/
ProxyPassReverse /sub1/ http://domain/sub1/

但没有任何运气。

有人可以就此提出任何建议吗?谢谢!

2 个答案:

答案 0 :(得分:0)

听起来您可能需要为sub1和sub2指定别名(和位置/目录)指令。

更一般地说,既然你似乎在运行同一个域中的所有内容,那么你应该使用mod_rewrite,而不是代理。

答案 1 :(得分:0)

以更简单的方式解决。由于我不关心用户在访问http://domain/时可以看到的地址行,因此我只使用了一个简单的RedirectMatch

RedirectMatch ^/$ /main
相关问题