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