IIS实现反向代理
场景如下
先说明一下场景,在一台服务器上,9999端口运行了hello应用,9998端口运行了bye应用,现需要通过80端口实现域名访问。
http://hello.com/hello ---> http://serverIp:9999/hello
http://bye.com/bye ---> http://serverIp:9998/bye
开始实现
安装ARR
- 下载
requestRouter_amd64.msi
并执行安装 - 下载
rewrite_amd64_zh-CN.msi
并执行安装
新建80端口网站
打开IIS,使用默认的80或者新建一个80的网站
增加两条URL重写规则
选择反向代理
输入最终转发到的网址(即被代理服务器ip:port)
注意:{HTTP_HOST}
为自带变量
同样方式配置bye映射
重启网站
实现效果
执行完毕,可通过域名对网站进行访问。
http://hello.com/hello
http://bye.com/bye
备选
可以通过直接配置web.config
实现
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="ReverseProxyInboundRule1">
<match url="^(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^hello.com$" />
</conditions>
<action type="Rewrite" url="http://localhost:9999/{R:1}" />
</rule>
<rule name="ReverseProxyInboundRule1">
<match url="^(.*)" />
<conditions>
<add input="{HTTP_HOST}" matchType="Pattern" pattern="^bye.com$" ignoreCase="true" negate="false" />
</conditions>
<action type="Rewrite" url="http://localhost:9998/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>