Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Without giving all the details, I'm trying to set up (via apache) two web applications that will be served from the same (internal development) server. Currently I have two VirtualHost directives and the two applications running on different ports. Instead, I'd like to have the URL determine which application is used, so, for example, myapp.domain.com will forward to one application and any other .domain.com will go to the other. Setting up the internal DNS to take care of that piece isn't a problem. But I'm not very familiar with apache, what's the best way to accomplish this?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

Within the <VirtualHost> you can use a ServerName; this is the directive to tell Apache to handle requests for that particular name. You can also use ServerAlias to specify other domains (and more besides!) that you'd like the VirtualHost to handle requests for.

For example, you can set up your directives like this

<VirtualHost ...>
    ServerName foo.example.com
    ...
    #Handle webapp1 in here
    ...
</VirtualHost>

<VirtualHost ....>
    ServerName example.com
    ServerAlias *.example.com
    ...
    #Handle webapp2 in here
    ...
</VirtualHost>

The Apache documentation contains several very good examples for most use cases in their documentation (http://httpd.apache.org/docs/2.0/vhosts/examples.html). You may also be interested in their "default" catchall halfway down the page, which is basically a catchall for any virtual host requests that aren't matched by previous directives.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.