redirect站点以更正主机上的VM

我想build立一些虚拟机less数的服务器上。 然后每个虚拟机将拥有不同的网站。 所以我的主机例如有DNS my.host.com,我会指向这个DNS例如其他的DNS地址,所以my.host.com – 1.2.3.4 my.host.com – virtual1.host.com my.host .com – virtual2.host.com

现在在私人networking上,VM的地址是:vm1 – 1.1.1.1 – 她持有网站virtual1.host.com vm1 – 2.2.2.2 – 她拥有网站virtual2.host.com

所以我的问题是如何我可以redirect到正确的虚拟机我的意思是如果我打virtual1.host.com我会去我的主机和主机应该redirect到我的网站。

我只想使用端口80或443.我可以使用什么防火墙或代理来进行此类redirect? 也许这将足以使用iptables来做到这一点,我也想到HAproxy?

有什么build议么 ? 和thx。

好男人我做了我想要的东道主我使用iptables,我放弃所有stream量在80至8080和443至8443的nginx代理然后从代理我发送到正确的地址。 vm(代理)和vm(站点)之间的通信总是在端口80上

我不得不在虚拟机上设置证书,在哪里是代理,并签署到适当的DNS,并通过proxy_pass发送到目的地是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 

那么我的nginx在chroot模式下运行,并有一个configuration:

 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; } } 

而Apache只监听端口80.所以所有与证书相关的计算都是在代理网站上完成的,而且Apache不会带来负担,而且caching机制必须给予我良好的性能,无论如何,我会在一段时间后看到。