Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have several machines on my lan. On of them is running 2 web sites, first_web_site and second_web_site (each one in a dedicated NameVirtualHost). Another machine is running another site third_web_site. I would like to be able to access each one, within internet, with the url:

  • first_web_site.domain.tld
  • second_web_site.domain.tld
  • third_web_site.domain.tld

knowing that 2 sites are on the same machine. Can Apache help me to do this ?

I have a machine that will have a apache server to be used for proxy purposes. I was talk to set up virtualhost on this one and use proxy server but I do not know how to do this.

Could you please give me hints ? Thanks a lot, Luc

share|improve this question

2 Answers 2

up vote 1 down vote accepted

Create or edit the vhosts.conf in your apache conf.d (or equivalent depending on OS).

Use the NameVirtualHost directive to handle the DNS names.

NameVirtualHost *:80

Then define each of your virtual hosts. Something like the following:

<VirtualHost *:80>
    ServerName sub1.domain.com
    ProxyRequests Off
    ProxyPreserveHost On

    # use the IP address or DNS or the server to forward to
    # can include the port as well if necessary
    ProxyPass / http://x.x.x.1/
    ProxyPassReverse / http://x.x.x.1/
</VirtualHost>

<VirtualHost *:80>
    ServerName sub2.domain.com
    ProxyRequests Off
    ProxyPreserveHost On

    ProxyPass / http://x.x.x.2/
    ProxyPassReverse / http://x.x.x.2/
</VirtualHost>

For the two sites on the same box, it depends on how they're setup. If they're on different ports, define the ports, if they're paths, then you'll need to add the path on the end of the ProxyPass and ProxyPassReverse entries:

http://x.x.x.1/app1
share|improve this answer
    
You could also wrap the ProxyPass and ProxyPassReverse directives in a Location directive. –  ahanson Mar 19 '10 at 21:54
    
Thanks for the configuration. –  David Rickman Mar 20 '10 at 11:03
    
Thanks tgm, I still have some pb: on my proxy machine, in ports.conf: " NameVirtualHost *:80 Listen 80 " and in my VirtualHosts: " <VirtualHost *:80> ServerName test.domain.tld ProxyRequests Off ProxyPreserveHost On ProxyPass / 192.168.1.150:81 ProxyPassReverse / 192.168.1.150:81 </VirtualHost> " and on the machine hosting the sites: <VirtualHost 192.168.1.150:81> ServerName test.domain.tld DocumentRoot /home/www/test/public </VirtualHost> <Directory "/home/www/test/public"> Options Indexes MultiViews AllowOverride None Order allow,deny Allow from all </Directory> –  Luc Mar 20 '10 at 14:07
    
hello, that's exactly what I needed, this is working fine. Thanks a lot. –  Luc Mar 21 '10 at 13:32

You could setup a proxy on the first box that connects and tunnels to the second one. This is so that the second box does all the heavy lifting, the first one will only need the resources to display the page.

share|improve this answer
2  
Sounds like he wants a combination of proxypass and virtualhosts. –  Nerdling Mar 19 '10 at 17:44

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.