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 would like to setup some server with few VM's on it. And then each VM will hold different site. So my host for example has DNS my.host.com, And I will point to this DNS for example to other DNS addresses so my.host.com - 1.2.3.4 my.host.com - virtual1.host.com my.host.com - virtual2.host.com

Now on private network VM's addresses are: vm1 - 1.1.1.1 - and she hold website virtual1.host.com vm1 - 2.2.2.2 - and she hold website virtual2.host.com

so my question is how i can redirect to correct VM I mean if I hit virtual1.host.com i will go to my host and host should redirect me to the site.

I want use only port 80 or 443. And what firewall or proxy I can use for this type redirection ? Also maybe it will be enough to use iptables to do this and I also was thinking about HAproxy ?

Any suggestions ? And thx.

share|improve this question
    
Welcome to Server Fault. The correct way to mark a question as solved is to click the outline of the check mark next to the answer that resolved your question, or if you solved it yourself, to post your own answer and accept it. You can also delete your question if it had no answers, but this isn't recommended. –  Michael Hampton Jan 27 '13 at 1:28
    
ah Sorry Michael I just saw your comment here i will do this thx ;) –  nonus25 Jan 28 '13 at 12:22
add comment

1 Answer 1

up vote 0 down vote accepted

ok guys i did what i want on host i was using iptables and i drop all traffic on 80 to 8080 and on 443 to 8443 for nginx proxy then from the proxy i am sending it to proper address. Communication between vm(proxy) and vm(site) is always on port 80

i had to setup certificate on VM where is proxy and sign it to proper dns and via proxy_pass send to destination there is example of confs:

iptables -t nat -A PREROUTING -d host_ip/32 -i eth0 -p tcp -m multiport --dports 80 -j DNAT --to-destination proxy_ip:8080
iptables -t nat -A PREROUTING -d host_ip/32 -i eth0 -p tcp -m multiport --dports 443 -j DNAT --to-destination proxy_ip:8443
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

then my nginx is running in chroot mode and there is a config:

server {
   listen       8080 ;
   server_name site_dns;
   rewrite        ^ https://$server_name$request_uri? permanent;
}

server {
  listen       8443 default_server;
  server_name site_dns;
  ssl on ;
  ssl_certificate /etc/nginx/server.crt;
  ssl_certificate_key /etc/nginx/server.key;
  access_log /var/log/nginx/site.access.log ;
  error_log  /var/log/nginx/site.error.log ;



  location / {
      proxy_pass  http://site_ip_vm;
      proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
      proxy_cache            one;
      proxy_cache_key         site$request_uri;
      proxy_cache_valid      200 3h;
      proxy_cache_use_stale  error timeout invalid_header updating http_500 http_502 http_503 http_504;
      proxy_ignore_headers   Expires Cache-Control;
      proxy_redirect http:// https://;
      proxy_buffering on;
      proxy_set_header        Host            $host;
      proxy_set_header        X-Real-IP       $remote_addr;
      proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

and apache is listen only on port 80. so all computing connected with certs is done on proxy site and apache is not burdened plus caching mechanism must give me good performance anyway i will see after a while.

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.