2011-02-25 51 views
5

我試圖創建一個虛擬主機dev.company.com,它根據域後的路由到達不同的應用程序。具體而言,我想:在命名虛擬主機中使用多個ServerPath指令

我使用以下配置:

<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服務器。正確的方法來做到這一點?

回答

8

所以使用ServerPath主要是爲傳統瀏覽器。這一招,然而,得到一個別名和重定向的虛擬主機的工作,你正在使用的包羅萬象:

ProxyPass/<url> 

是告訴的ProxyPass忽略某些路徑:ProxyPass /path !符號

所以我最後虛擬主機是這樣的:

<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 
相關問題