客户端未通过IIS节点从SocketIO接收事件

dev*_*ebz 7 iis node.js express socket.io iisnode

我有一个Web应用程序,它与通过IIS节点托管的NodeJS服务器建立套接字连接.当我解决了我最初拥有的客户端上的404轮询错误时,似乎连接正常.但是现在看起来客户端没有从IIS节点接收套接字事件.

我的理论是,因为IIS节点就像一个代理,发送回客户端的事件正在IIS节点级别停止.

exports.register = function(socket) {
    User.schema.post('save', function (doc) {
        console.log("Save socket");
        onSave(socket, doc);
    });
}

function onSave(socket, doc, cb) {
    socket.emit('User List Update', doc);
}
Run Code Online (Sandbox Code Playgroud)

在Node中,上述事件触发,但在前端未收到.

客户端看起来像这样:

var socket = io.connect("http://myinternallyhostedserver:7777/reception");

socket.on('User List Update', function () {
  console.log('Received socket event!');
  if (vm.enableAlert) {
      vm.alertSound.play();
  }
  vm.getUsers();
});
Run Code Online (Sandbox Code Playgroud)

我的web.config文件如下所示:

<configuration>
    <appSettings>
        <add key="virtualDirPath" value="/reception" />
    </appSettings>
    <system.webServer>
        <handlers>
            <add name="iisnode" path="server/app.js" verb="*" modules="iisnode" />
        </handlers>
        <iisnode enableXFF="true" />
        <webSocket enabled="false"/>
        <rewrite>
            <rules>
                <rule name="reception">
                    <match url="/*" />
                    <action type="Rewrite" url="server/app.js" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)

在我的本地计算机上运行所有这些工作正常.发送和接收套接字事件.将IIS节点添加到工作流程似乎是它停止工作的地方.任何帮助将不胜感激.

Emr*_*ğlu 2

在将socket.io与proxy pass一起使用时,您需要传递一些变量,例如升级等。我什至没有尝试使用iis来代理pass socket.io,但我在apache proxy pass中遇到了一些问题。因此我选择nginx作为代理服务器。

也许你需要在iis中写入此类参数,或者你可以使用nginx作为代理服务器。

location / {
        proxy_pass http://socket_nodes_2/doSomething;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_redirect off;

        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

upstream socket_nodes_2 {
    server 192.168.1.155:1338;
    server 192.168.1.156:1338;
}
Run Code Online (Sandbox Code Playgroud)