Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using multiple ServerPath directives inside a Named VirtualHost

Tags:

apache2

I'm trying to create a virtual host, dev.company.com, that routes to different applications depending on what comes after the domain. Specifically, I want:

  • /jenkins - to route to a Jenkins server
  • /apps - to route to a landing page with links to various applications
  • /clover - to route to a particular Jenkins build report - http://dev.company.com/jenkins/job/proj-master-clover/clover/
  • / - everything else should route to a Tomcat server

I'm using the following config:

<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 works fine, but /apps and /clover always redirect to the Tomcat server. Is the right way to do this?

like image 982
Bradley Avatar asked Feb 25 '11 15:02

Bradley


People also ask

What does VirtualHost *: 80 mean?

VirtualHost directive allows you to configure and use multiple sites located on the same IP address. In this case, with *:80 you are creating a virtual host for every request coming on the port 80. It becomes more interesting when you start specializing and start to insert something other than * in the virtual host.

How do you name a virtual host?

To use name-based virtual hosting, you must designate the IP address (and possibly port) on the server that will be accepting requests for the hosts. This is configured using the NameVirtualHost directive.


1 Answers

So using ServerPath's is mostly for legacy browsers. The trick, however, to getting an Alias and a Redirect working in a VirtualHost where you're using the catch-all:

ProxyPass / <url>

is tell ProxyPass to ignore certain paths: ProxyPass /path ! notation

So my final VirtualHost looks like this:

<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>

and the urls are:

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
like image 135
Bradley Avatar answered Oct 21 '22 17:10

Bradley