我试图在我的 apache 服务器上托管多个网站(app.diff1.com 和 app.diff2.com 在 tomcat 服务器上运行),它们分别在端口 8082 和 8083 上运行,为了访问它们我想使用一个域名 (app.in.xxx.com/diff) 以及区分符 (diff1/diff2)。我使用 url 重写分别更改域名。现在,当我尝试访问网站时,我总是以访问第一个虚拟主机告终。 如果我没有正确地接近解决方案,请给我建议。
代码片段:
在 httpd.conf 文件中。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^app\.in\.xxx\.com/([a-z]*)$
RewriteRule ^ http://www.app.%1.com [L,R=301]
</IfModule>
<IfModule mod_proxy.c>
ProxyRequests off
</IfModule>
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.app.diff1.com
ProxyPass / http://www.app.diff1.com:8082/
ProxyPassReverse / http://www.app.diff1.com:8082/
</VirtualHost>
<VirtualHost *:80>
ServerName www.app.diff2.com
ProxyPass / http://www.app.diff2.com:8083/
ProxyPassReverse / http://www.app.diff2.com:8083/
</VirtualHost>
最佳答案
将您的重写移动到第一个列出的虚拟主机中,并停止 try catch URL 的第一个路径组件,就好像它是 HTTP_HOST 的一部分一样——在 RewriteRule 本身中捕获它并使用 $1。
另请参阅 ServerPath,这是一种进行相同映射的深奥方式。
关于apache - 在一个 ip 地址下在 apache 上托管多个网站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18045312/