如何根据主机名在相同的IP上切换不同的Web服务器?

在我的地方,我有4台服务器,每台服务器都运行Win2008r2-WEB作为web服务器,运行着不同types的服务器(TomCat,IIS,Apache,ZendServer),每台服务器也有不同的IP地址(10.0.0.0/24)

有没有办法根据主机名将stream量路由到每台服务器? (例如:apache.domain.org,iis.domain.org,tomcat.domain.org,zend.domain.org)

显然,我不能将Alogging更改为内部IP,并且我无权访问更改端口。

另外由于代理原因,我不能只使用其他端口,我只能访问:80来电。

你需要做的就是让现有的Web服务器(或专门用于该任务的单独服务器)configuration为反向代理。

它将负责获取公共地址上的请求并读取主机头,然后根据请求的主机将请求代理到适当的私有地址。

这个任务常用的软件包有Apache(你可以使用你现有的实例),nginx或者HAProxy。 这里有很多关于如何正确configuration这些问题的信息(“ 反向代理 ”是能够帮助你的search词),但是如果你有一个特定的软件包,那么我可以用一个例子编辑这个答案configuration。

编辑 :例如Apacheconfiguration:

NameVirtualHost *:80 <VirtualHost *:80> ServerName apache.domain.org ServerAlias www.apache.domain.org # For this one, we'll imagine that you want to serve these resources from # the local server. If you want do use a separate Apache instance instead, # then copy one of the other hosts for this one. DocumentRoot "C:\path\to\site\files" <Directory "C:\path\to\site\files"> Order allow,deny Allow from all </Directory> # Any other directives you need for the content here </VirtualHost> <VirtualHost *:80> ServerName iis.domain.org ServerAlias www.iis.domain.org # Replace the URL below with the URL of the IIS server - make sure # to keep the trailing slash. ProxyPass / http://10.xx1:80/ ProxyPassReverse / http://10.xx1:80/ </VirtualHost> <VirtualHost *:80> ServerName tomcat.domain.org ServerAlias www.tomcat.domain.org # Replace the URL below with the URL of the Tomcat server - make sure # to keep the trailing slash. ProxyPass / http://10.xx2:8080/ ProxyPassReverse / http://10.xx2:8080/ </VirtualHost> 

基于名称的虚拟主机是不是一个选项的原因是什么?

http://httpd.apache.org/docs/2.0/vhosts/name-based.html

10.x地址是内部地址,正如你所说,DNS不会帮你。 所有服务器是否都响应相同的外部IP地址? (然后,您可以为DNS中的每个子域创buildAlogging,每个子域指向相同的IP …或更好,使用CNAMES。)

至less在IIS中,您可以使用主机头来检测哪个网站应根据DNS名称进行响应。 因此,如果您希望IIS站点1响应“testsite1.com”和“www.testsite1.com”等站点,只需将其添加到指定IIS站点的主机头中。 然后在第二个iis站点上,您可以将“testsite2.com和www.testsite2.com”作为签名,IIS将在这些域上提取。 DNS到主机头的A到CNAME是无关紧要的。 IIS将与这两个工作。

通常我们用IIS做什么,我们是为它自己的servername创build一个Alogging,然后我们使用CNAME来转发到服务器名称Alogging。

所以Webserver A = 10.10.10.10 testsite1.com CNAME = webserver testsite2.com CNAME = webserver

然后,IIS将知道在哪里发送基于DNS名称的网站。