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.

I use a very simple /etc/apache2/sites-enabled/000-default configuration like

<VirtualHost 117.121.241.184>
UseCanonicalName    Off
VirtualDocumentRoot /srv/www/%0
Options All ExecCGI
LogFormat "%V %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" vhost_common
CustomLog /var/log/apache2/access.log vhost_common
</VirtualHost>

Where 117.121.241.184 is the IP of my machine I'm setting upon.

Now I want to do something a little complicated, i.e. proxy a NodeJS instance like so:

<VirtualHost foobar.example.com:80>
 <Location />
   ProxyPass http://localhost:3000/
   ProxyPassReverse http://localhost:3000/
 </Location>
</VirtualHost>

And it doesn't work. Apache just serves /srv/www/foobar.example.com. If I put the "VirtualHost foobar.example.com" stanza above the VirtualDocumentRoot one, then everything gets redirected to the proxy, which I don't want.

I just want the particular domain "foobar.example.com" handled by the proxy, and everything else, the VirtualDocumentRoot.

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

What you're looking to configure is name-based virtual hosting, where the virtual host is selected based on the Host header sent in the HTTP request by the client.

To do this, you'll need a NameVirtualHost directive, and for your <VirtualHost> blocks to match exactly to what you've configured in it. For instance:

NameVirtualHost *:80
<VirtualHost *:80>
  ServerName default
  VirtualDocumentRoot /srv/www/%0
  # other needed config directives here
</VirtualHost>
<VirtualHost *:80>
  ServerName foobar.example.com
  <Location />
    ProxyPass http://localhost:3000/
    ProxyPassReverse http://localhost:3000/
  </Location>
</VirtualHost>
share|improve this answer
    
thank you, so the ServerName seems key here. :) –  hendry Jan 11 '13 at 8:39
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.