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.

I have a router that forwards all port 80 to a Debian web server, but I want to add another server to that bunch. How could I get debian to say forward anyone trying to access git.domain.com to 192.168.0.21 or what ever (so git.domain.com would go to the standard IP just be forwarded to another local server, such that it will have a FQDN)?

share|improve this question

3 Answers 3

You could use the proxy_mod and vhosts for apache on the server that gets hit with the traffic first.

The fist virtual host would just serve the local content. The second virtual host would be a proxy for the content stored on the other server. You vhost would be similar to this:

ServerName git.domain.com
        DocumentRoot /var/www/
        ProxyRequests Off
          Order deny,allow
          Allow from all
        ProxyPass / http://192.168.0.21:80/
        ProxyPassReverse / http://192.168.0.21:80/
share|improve this answer
    
So would DocumentRoot be where it is on the other server? Or just whatever? –  Steven Feb 10 '12 at 13:26
    
Whatever, proxy will take over anyway, but I think you must provide the field for the config-check to be happy. –  Bart De Vos Feb 10 '12 at 13:29

Port forwarding works with IP addresses and ports, not hostnames, so in short - you can't. Presuming you have multiple DNS entries pointing to the same public IP address, the router would somehow have to inspect the HTTP requests to decide which internal webserver to send it to - which is out of scope of all home networking gear I would have thought.

The only way you could do this would be to have multiple public IPs, with each one being forwarded to a different webserver internally, or to port forward a different port (say, 81) for the other webserver.

share|improve this answer
    
Or, use a proxy-server... This is common practice. –  Bart De Vos Feb 10 '12 at 13:22
    
Which I would have suggested, however the initial question asked about it from a port forwarding point of view. –  Andy Smith Feb 10 '12 at 13:24

One of the simplest ways to do this would be to run a reverse proxy, such as haproxy. You can operate this on the Debian server, and then forward on requests to where you desire.

So a brief example: your proxy listens on port 80, and forwards everything for a.example.com to an apache instance listening on 127.0.0.1:8080, and everything for b.example.com to an apache instance on another machine (e.g. 192.168.0.21:80).

The documentation on the haproxy website is simple to understand so you can apply to your circumstances: http://haproxy.1wt.eu. Note, that there will be lots of info not relevant to you, as haproxy can do a lot more than this simple task.

share|improve this answer

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.