Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

i have an Apache server running for two sites on port 80. Let's say the domain is example.com and I have an other domain example2.com. When a user visits example.com, I want it to serve those files (so a virtual host) but when someone tries to access the domain example2.com (that is on the same IP Address), I want it to redirect to another IP address on port 90 without the visitor knowing that he is on a different port.

How can I achieve this?

<VirtualHost example.com:80>   
 DocumentRoot {rootdir}  
 ServerName example.com  
 ServerAlias example.com 
</VirtualHost>   
<VirtualHost *:80>   
  NoProxy .example.com  
  ProxyPreserveHost On  
  ProxyRequests Off  
  ServerName *  
  ProxyPass / http://server2:90  
  ProxyPassReverse / http://server2:90  
</VirtualHost>  

This won't work and it tries to get example.com with the proxy too, does anyone know why?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Are you sure you want to redirect your users? From what I understand, you want server example2.com to proxy to somewhere else. You can setup Apache as a proxy with mod_proxy. And you can also define this proxy for a specific VirtualHost, see Apache's VirtualHost Examples.

For example something like this should work:

NameVirtualHost *:80
<VirtualHost *:80>
    ServerName example.com
<VirtualHost>
<VirtualHost *:80>
    ServerName example2.com
    ProxyPass / http://server2:90/
    ProxyPassReverse / http://server2:90/
    ProxyPreserveHost On  
    ProxyRequests Off
<VirtualHost>

also make sure mod_proxy is loaded

LoadModule proxy_module modules/mod_proxy.so
share|improve this answer
    
Lets say i have 2 different servers, one apache (for myself) and one nginx (for an other site). The requests come in on the apache server, and for one site need to be handeled by apache and the other by nginx. But the proxy will work. Thank you for the help! :) –  Christiaan de Die Jun 15 '13 at 16:50
    
It doesn't work yet, and i edited it. Can you take an other look for me please? –  Christiaan de Die Jun 15 '13 at 17:17
    
You say "doesn't work" but don't provide any detail on what happens. This is not very helpful. Please provide relevant description of what happens, why it isn't what you expected, and server log entries if needed. It looks like you're putting together some pieces of code you don't try to understand. Please refer to Apache manual for the details, for instance the doc of ProxyPass says If the first argument ends with a trailing /, the second argument should also end with a trailing / and vice versa. I edited my original answer with a configuration that should work. –  Calimo Jun 17 '13 at 7:38

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.