![使用 IIS 8.5 和 URL rewrite 2.0 可以实现 websocket 反向代理吗?](https://linux22.com/image/653185/%E4%BD%BF%E7%94%A8%20IIS%208.5%20%E5%92%8C%20URL%20rewrite%202.0%20%E5%8F%AF%E4%BB%A5%E5%AE%9E%E7%8E%B0%20websocket%20%E5%8F%8D%E5%90%91%E4%BB%A3%E7%90%86%E5%90%97%EF%BC%9F.png)
我在 IIS 后面安装了 Tomcat 作为 Java 应用服务器。使用以下规则,我可以很好地重写静态页面,但遗憾的是,Websocket 连接从未建立:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<webSocket enable="false"/>
<rewrite>
<rules>
<rule name="Redirect HTTP to HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/foo/{R:1}" redirectType="SeeOther" />
</rule>
<rule name="Redirect from IIS to Tomcat" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{CACHE_URL}" pattern="^(.*)://" />
</conditions>
<action type="Rewrite" url="{C:1}://tomcat.contoso.com/foo/{R:1}" />
</rule>
</rules>
<outboundRules>
<rule name="Redirect from Tomcat to IIS" preCondition="ResponseIsHtml">
<match filterByTags="A, Form, Img" pattern="^(.*)://tomcat.contoso.com/foo/(.*)" />
<action type="Rewrite" value="{R:1}://apps.contoso.com/foo/{R:2}" />
</rule>
<preConditions>
<preCondition name="ResponseIsHtml">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
</system.webServer>
</configuration>
有人成功了吗? URL 重写是否甚至支持 websockets (ws:// & wss://) 反向代理?