IIS 7 反向代理背后的 Websocket 服务器
我已经使用 .NET 4.0 和套接字使用 hybi-17 规范构建了一个 WebSocket 聊天服务器。如果浏览器通过端口 81 连接到聊天服务器,一切都会正常运行。然而,由于公司防火墙等原因 - 我需要浏览器连接到端口 80,因为世界上的每台 PC 都需要访问该端口。
所以我使用 IIS 7 作为反向代理。我已设法让浏览器连接到 IIS 7 上的 ws://localhost/chatProxy,然后将请求代理到 http://localhost:81/chatProxy 其中 websocket 服务器正在侦听。
Websocket 服务器进行握手并为连接创建套接字,然后返回侦听状态。
问题是,在客户端,websocket“onopen”事件永远不会被触发。就好像 IIS 没有将请求发送回浏览器一样。
任何帮助将不胜感激!
提前致谢!!
I've build a WebSocket chat server using the hybi-17 spec using .NET 4.0 and Sockets. If the browser connects to the chat server on port 81, everything functions as it should. However due to company firewalls etc. - I need to browser to connect to port 80 as this needs to be accessible to every PC in the world.
So I'm using IIS 7 as a reverse proxy. I have managed to get the browser to connect to ws://localhost/chatProxy on IIS 7 which then proxies the request to http://localhost:81/chatProxy where the websocket server is listening.
The Websocket server does the handshake and creates a socket for the connection, then goes back into a listening state.
The problem is, on the client side the websocket "onopen" events is never triggered. It's as if IIS doesn't send the request back to the browser.
Any help will be highly appreciated!!
Thanks in advance!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为 IIS 7 不知道 websockets 并且无法代理它。然而,它会将初始请求转发到您的 websocket 服务器,因为对 websocket 服务器的初始请求是标准 HTTP 请求(带有一些附加标头)。 IIS 会知道这一点并简单地转发请求。但是,在收到 websocket 请求后,websocket 服务器将发送 101 响应并切换到 websocket 模式。 IIS 无法理解 websocket 流量,也无法对其进行代理。
IIS 8 将原生支持 websocket(支持将包含在 .NET 4.5 中),并且希望 Microsoft 也将添加对反向代理 websocket 流量的支持。
This is because IIS 7 does not know about websockets and is not able to proxy it. It will however forward the initial request to your websockets server as the initial request to a websocket server is a standard HTTP request (with some additional headers). IIS will know about that and simply forward the request. However, upon receiving the websocket request the websocket server will send a 101 response and switch into websocket mode. IIS will not understand the websocket traffic and will not be able to proxy that.
IIS 8 will natively support websockets (support will be included in .NET 4.5) and hopefully Microsoft will also add support to reverse proxy websocket traffic.