我目前有一个硬件linux服务器与一个IP地址运行三个网站(虚拟主机通过Apache)。 我想推动每个网站到自己的虚拟机,以提高隔离/安全性,并更容易迁移到不同的硬件,如果需要的话。 (我正在为此检查coreos。)
但是我很困惑这个简单的问题。 如何将不同的虚拟主机httpd(或ssh或…)请求推送到同一IP硬件上的不同虚拟机? 这不是一个DNS级别的问题—我的DNS提供商只把我的访问者推到主IP上,我想。
build议感激。
问候,
/ IAW
您可以设置代理服务器,根据虚拟主机规则将stream量redirect到虚拟服务器。 Apache为此具有mod_proxy,您可以设置一个反向代理/网关,根据虚拟主机匹配将HTTPstream量redirect到正确的虚拟机。
您需要在主机上安装反向代理服务器。 有好几个好的。 Apache与mod_proxy例如:
<VirtualHost external_IP:80> ServerName cust1.dev.domain.com ServerAdmin [email protected] ProxyRequests off ProxyPreserveHost on ProxyPass / http://192.168.0.100/ ProxyPassReverse / http://192.168.0.100/ <Proxy *> Order allow,deny Allow from all </Proxy> ErrorLog /var/log/apache2/cust1.dev.domain.com.log CustomLog /var/log/apache2/cust1.dev.domain.com.err.log combined </VirtualHost> <VirtualHost external_IP:80> ServerName cust2.dev.domain.com ServerAdmin [email protected] ProxyRequests off ProxyPreserveHost on ProxyPass / http://192.168.0.101/ ProxyPassReverse / http://192.168.0.101/ <Proxy *> Order allow,deny Allow from all </Proxy> ErrorLog /var/log/apache2/cust2.dev.domain.com.log CustomLog /var/log/apache2/cust2.dev.domain.com.err.log combined </VirtualHost>
或者你可以用nginx做到这一点:
upstream vm1 { server 192.168.1.100:80; #VM1 } upstream vm2 { server 192.168.1.101:80; #VM2 } ## Start VM1 ## server { listen external_IP:80; server_name www.example.com; access_log /var/log/nginx/log/www.example.access.log main; error_log /var/log/nginx/log/www.example.error.log; root /usr/share/nginx/html; index index.html index.htm; ## send request back to apache1 ## location / { proxy_pass http://vm1; proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504; proxy_redirect off; proxy_buffering off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } ## START VM2 ## server { listen external_IP:80; server_name static.example.com; access_log /var/log/nginx/log/static.example.com.access.log main; error_log /var/log/nginx/log/static.example.com.error.log; root /usr/local/nginx/html; index index.html; location / { proxy_pass http://vm2; proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504; proxy_redirect off; proxy_buffering off; proxy_set_header Host static.example.com; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
不同的主机需要有不同的IP地址。 您可能能够与NAT和网站的代理服务器一起黑客攻击。 每个服务器的SSH必须位于不同的端口上。
为每个服务器分配正确的IP地址要好得多。 在单独的服务器上托pipe网站是请求更多IP地址的有效理由。