IIS路由请求到基于子域的不同端口

问题描述 投票:-1回答:2

我有一个域,我们称它为domain.com

在我的DNS提供程序上,我已经配置了两个子域以指向相同的IP地址。例如:sub1.domain.com=>185.146.11.17sub2.domain.com => 185.146.11.17

我在IIS中配置了两个站点,分别侦听端口8080和8081。

现在,由于流量直接在185.146.11.17:80上通过,我需要根据请求的子域将其路由到端口8080或端口8081

我已经阅读了重写规则和反向代理,但是对于如何基于请求的子域简单地实现我所需要的东西感到完全困惑。

人们如何做到这一点?

iis reverse-proxy url-rewrite-module
2个回答
0
投票

听起来您需要为其本身创建ARR负载平衡。

先决条件

1。安装了应用程序请求路由和URL重写。

2。三个DNS名称,一个用于前端,两个用于后端。

enter image description hereenter image description here

3。具有域名的三个网站:

主站点

enter image description here

SubSite1

enter image description here

SubSite2

enter image description here

4。创建一个Web场并将这些域添加到您的Web场中。enter image description here

  1. IIS将在服务器节点的URL重写中创建负载平衡路由规则“ ARR_MyServer_loadbance”,然后为其添加条件模式。

enter image description here

 <globalRules>
                <rule name="ARR_MyServer_loadbalance" patternSyntax="Wildcard" stopProcessing="true">
                    <match url="*" />
                    <action type="Rewrite" url="http://MyServer/{R:0}" />
                    <conditions>
                        <add input="{HTTP_HOST}" pattern="www.candy.com" />
                    </conditions>
                </rule>
            </globalRules>

6。转到配置管理器-> Web场并将PreserveHostHeader设置为false。enter image description here7.转到您的Web场->我的服务器监视和代理,确保所有服务器都正常现在您可以为您的主站点进行负载平衡。

enter image description here

只需记住在将服务器加入Web场时为每个服务器设置HTTP端口。enter image description here

Applicationhost.config应该看起来像:

  <webFarm name="MyServer" enabled="true">
            <server address="domain1.candy.com" enabled="true">
                <applicationRequestRouting httpPort="8080" />
            </server>
            <server address="domain2.candy.com" enabled="true">
                <applicationRequestRouting httpPort="8081" />
            </server>
            <applicationRequestRouting>
                <healthCheck url="" />
                <protocol preserveHostHeader="false" />
            </applicationRequestRouting>
        </webFarm>

0
投票

经过大量的挖掘,反复试验并拔出头发,我设法解决了这个问题。在这种情况下,IIS似乎为它提供了很多繁重的工作,并且实际上并不需要任何显式的反向代理和/或重写规则。

DNS设置如下sub1.domain.com=>185.146.11.17sub2.domain.com => 185.146.11.17

所有需要做的是:1.停止/删除端口80上的默认网站。2.通过以下方式创建新网站:2.1。站点名称设置为sub1.domain.com。2.2。 IP地址设置为All Unassigned,端口设置为80。2.3。主机名设置为sub1.domain.com。3.用sub2.domain.com重复该过程。

按照上述步骤,所有这些都应该神奇地工作。主机名非常重要,因此请确保不要错过这些主机名。我建议将其全部设置为HTTPS,然后创建请求从HTTP重定向的规则(如果此类协议中出现了请求)。

感谢大家提供建议。

© www.soinside.com 2019 - 2024. All rights reserved.