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.

hi I have 3 apache servers but one inbound ip with one port 80 to listen on. all port 80 traffice goes to 192.168.1.10. But I want to vhost to send certaindomains like www.mydomain.co.uk to the local folders required, and certain domains to offserver to server2 (192.168..1.11) and this works for domains wiki.mydomain.co.uk it works perfectly but what I ALSO want to do is send all the "spare" unknown traffic to 192.168.1.12 and this ISN'T working as I would hope.

All I want to do is send traffic that isn't listed to the server 192.168.1.12. When I do a port check on the machine 192.168.1.12 nothing is arriving.

NameVirtualHost *:80

Alias /errors/ /var/www/html/mydomain/errors/

<VirtualHost *:80>
  ServerName www.mydomain.co.uk
  DocumentRoot /var/www/html/mydomain/www
  ErrorDocument 404 /errors/404error.php
</VirtualHost>

<VirtualHost *:80>
  ServerName admin.mydomain.co.uk
  DocumentRoot /var/www/html/mydomain/admin
</VirtualHost>

<VirtualHost *:80>
  ServerName wiki.mydomain.co.uk
  ServerAdmin root@localhost
  ProxyRequests Off
  ProxyPreserveHost On
  ProxyPass / http://192.168.1.11/
  ProxyPassReverse / http://192.168.1.11/
  <Proxy *>
    Order allow,deny
    Allow from all
  </Proxy>
  ErrorLog /var/log/httpd/wiki.mydomain.co.uk.log
  CustomLog /var/log/httpd/wiki.mydomain.co.uk.err.log combined
</VirtualHost>

<VirtualHost _default_:80>
   ProxyPreserveHost On
   ProxyPass / http://192.168.1.12/
   ProxyPassReverse / http://192.168.1.12/
</VirtualHost>

apachectl -S

VirtualHost

 configuration:
wildcard NameVirtualHosts and _default_ servers:
_default_:443          www.mydomain.co.uk (/etc/httpd/conf.d/ssl.conf:74)
*:80                   is a NameVirtualHost
         default server www.mydomain.co.uk (/etc/httpd/conf.d/vhost.conf:5)
         port 80 namevhost www.mydomain.co.uk (/etc/httpd/conf.d/vhost.conf:5)
         port 80 namevhost www.mydomain.co.uk (/etc/httpd/conf.d/vhost.conf:12)
         port 80 namevhost admin.mydomain.co.uk (/etc/httpd/conf.d/vhost.conf:18)
         port 80 namevhost wiki.mydomain.co.uk (/etc/httpd/conf.d/vhost.conf:23)
share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Place the default vhost first in the configuration file.

The first vhost will be used if no match against the Host: sent is found. In your case that means this should be top:

<VirtualHost *:80>
   ProxyPreserveHost On
   ProxyPass / http://192.168.1.12/
   ProxyPassReverse / http://192.168.1.12/
</VirtualHost>

(I've dropped the "_default_" because it is redundant.)

share|improve this answer
    
thanks Steve, when I do this everything gets redirected and all the vhosts fail :-/ –  user26676 Jan 1 '13 at 21:40
    
@user26676 Provide the output from apachectl -S? –  Shane Madden Jan 1 '13 at 21:46
    
yes, I ran it for you, see edit –  user26676 Jan 1 '13 at 22:47
1  
hmm it appears it's only the www that is failing: (the others admin and wiki work) so it appears my www is wrongly set up (and hitherto been working incorrectly as a default (so still "working")) but I don't see how it's different. –  user26676 Jan 1 '13 at 22:53
    
the issue was the ServerName was www.mydomain.co.uk. in httpd.conf - renamed the ServerName and it's fine –  user26676 Jan 2 '13 at 8:51
show 1 more 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.