I have a web server that it set up to dynamically server different document roots for different domains
<VirtualHost *:80>
<IfModule mod_rewrite.c>
# Stage sites :: www.[document root].server.company.com => /home/www/[document root]
RewriteCond %{HTTP_HOST} ^www\.[^.]+\.server\.company\.com$
RewriteRule ^(.+) %{HTTP_HOST}$1 [C]
RewriteRule ^www\.([^.]+)\.server\.company\.com(.*) /home/www/$1/$2 [L]
</IfModule>
</VirtualHost>
This makes it so that www.foo.server.company.com
will serve the document root of server.company.com:/home/www/foo/
For one of these sites, I need to add a ProxyPass
, but I only want it to be applied to that one site. I tried something like
<VirtualHost *:80>
<Directory /home/www/foo>
UseCanonicalName Off
ProxyPreserveHost On
ProxyRequests Off
ProxyPass /services http://www-test.foo.com/services
ProxyPassReverse /services http://www-test.foo.com/services
</Directory>
</VirtualHost>
But then I get these errors
ProxyPreserveHost not allowed here
ProxyPass|ProxyPassMatch can not have a path when defined in a location.
How can I set up a ProxyPass
for a single virtual host?
Just move the
ProxyPass
out of the<Directory>
block - if it's in that context, it's expected that it applies to that exact context (instead of the/services
you want it to apply for).Actually, you're not doing anything with that block at all, it looks like?
edit: Missed that it's not actually virtual hosts - your example where it's just a directory in a virtual host block made me think they were separate.
In that case...
Use a New VirtualHost
If you add a new
VirtualHost
above your current one and specify the domain inServerName
, you can then proxy that specific domain.You may need to add a
NameVirtualHost
if you are on Apache prior to version 2.3.11.I recommend setting
ProxyRequests Off
at the server level.When Apache tries to match domain names it does so on a first match basis. The first match (VirtualHost, ServerName, or ServerAlias) in the configuration file will be the one used to route the traffic. There is no special treatment for wildcards, so any specific server name declarations need to appear before your wildcard virtual host.
ProxyPreserveHost
is permitted only in the Server and VirtualHost context. So if you must use that directive, you will need to place it in a new VirtualHost.