Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Scenario:

Due to limited number of IPs, several domains are resolved into the same IP address. However, these domains may not all run on the same webserver, VM, or even dedicated machine. Therefore, I would like to route the domains at the point of entry into the private network to the right place on condition of the domain in the url.

How can I do this?

share|improve this question
add comment

4 Answers

up vote 3 down vote accepted

Most routers/firewalls allow to redirect traffic based on a certain port, e.g. all SMTP traffic (port 25) is redirected to 192.168.1.1.

But if you have multiple servers to handle your traffic (1 server per domain). You need to install something like a reverse proxy (nginx supports this for HTTP, IMAP, POP3). For instance, all traffic to port 80 is redirected to 192.168.1.2 which runs nginx and depending on the host name will redirect to either localhost or 192.168.1.4.

share|improve this answer
    
+1 Nginx is perfect for this as it doesn't use much memory and was designed to handle large numbers of requests. It's pretty easy to setup on most distros. –  Frozenskys Aug 12 '10 at 13:32
    
+1 Apache is definitely overkill. A simple Nginx proxy will get the job done. –  Scott Anderson Aug 12 '10 at 15:38
    
I have installed nginx. It was very easy to install and configure and works very good. –  txwikinger Oct 7 '10 at 20:09
add comment

I am unsure if I fully understand your question. If I do, you have multiple machines running as HTTP servers behind NAT. When some request arrives, you want to forward it to one of your servers, right?

If you are using apache and mod_rewrite, you might be able to pull it this way:

  1. http://www.linuxquestions.org/questions/linux-networking-3/apache-forward-request-to-another-box-264864/

  2. http://www.sematopia.com/2007/09/apache-forwarding-requests-to-another-server/

Cheers.

share|improve this answer
    
I don't think I can use rewrite to the ip-address since this would prevent me to use multiple domains in one VM, however, I probably can rewrite into local sub domains. –  txwikinger Aug 11 '10 at 18:25
add comment

I was looking for the same thing a while ago. Never got around to do it but here is what I though might work.

use the mod_proxy module and use the noproxy directive.

http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#noproxy

share|improve this answer
    
I used to have troubles with mod_proxy, but I might try this again. –  txwikinger Aug 11 '10 at 18:22
add comment

I have done something similar using the ProxyPass directive under mod_proxy in Apache.

First of all, use Name-based Virtual Hosting to allow different domains to be host different sites using the same IP, then for the domains that associated to an internal webserver, you have a config like so:

# Within your VirtualHost definition
ServerName somedomain.com
ProxyPass / http://10.0.1.42/
ProxyPassReverse / http://10.0.1.42/

This will result in all requests to http://somedomain.com be transparently proxied to an internal site hosted on http://10.0.1.42.

HTH

share|improve this answer
add 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.