我正在尝试创建一个虚拟主机dev.company.com,它根据域之后的内容路由到不同的应用程序。具体来说,我想:
我正在使用以下配置:
<VirtualHost *:80>
ServerName dev.company.com
ServerPath /jenkins
ProxyPass /jenkins http://easyrider:8080/jenkins
ProxyPassReverse /jenkins http://easyrider:8080/jenkins
ServerPath /clover
Redirect /clover http://dev.company.com/jenkins/job/proj-master-clover/clover/
ServerPath /apps
DocumentRoot "/usr/local/sites/developers"
<Directory "/usr/local/sites/developers">
DirectoryIndex index.html
Options Indexes MultiViews
</Directory>
ServerPath /
ProxyPass / http://tomcat_server:8080/
ProxyPassReverse / http://tomcat_server:8080/
</VirtualHost>
http://dev.company.com/jenkins工作正常,但/ apps和/ clover总是重定向到Tomcat服务器。这是正确的方法吗?
答案 0 :(得分:10)
因此,使用ServerPath主要用于旧版浏览器。然而,诀窍是让Alias和Redirect在VirtualHost中工作,你正在使用catch-all:
ProxyPass / <url>
告诉ProxyPass忽略某些路径:ProxyPass /path !
表示法
所以我的最终VirtualHost看起来像这样:
<VirtualHost>
ServerName dev.company.com
ProxyPass /jenkins http://easyrider:8080/jenkins
ProxyPassReverse /jenkins http://easyrider:8080/jenkins
# Tells ProxyPass to ignore these paths as they'll be handled by Alias and Redirect
ProxyPass /clover !
ProxyPass /apps !
Redirect /clover http://dev.company.com/jenkins/job/proj-master-clover/clover/
Alias /apps "/usr/local/sites/developers"
<Directory "/usr/local/sites/developers">
DirectoryIndex index.html
Options Indexes MultiViews
</Directory>
ProxyPass / http://tomcat_server:8080/
ProxyPassReverse / http://tomcat_server:8080/
</VirtualHost>
并且网址是:
http://dev.company.com/jenkins* - will proxy to jenkins http://dev.company.com/jenkins
http://dev.company.com/apps - will proxy to http://dev.company.com/apps/
http://dev.company.com/clover - will redirect to http://dev.company.com/jenkins/job/proj-master-clover/clover/
and everything else will go to tomcat at tomcat_server:8080