首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Azure中托管的节点服务器上的Websockets失败

Azure中托管的节点服务器上的Websockets失败
EN

Stack Overflow用户
提问于 2021-06-18 15:44:18
回答 1查看 228关注 0票数 3

我有一个简单的barebone示例,它可以在本地运行,但不能在Azure中运行。我最初的问题有点针对一个cors错误,我现在已经解决了这个问题,并因此编辑掉了这一部分。但是我仍然不能让WS在azure上工作。我需要帮助。

代码语言:javascript
运行
复制
var server = http.Server(app);
const wss = new WebSocket.Server({server});

server.listen(8070, () => {
  console.log("Listening on " + port)
});


wss.on('connection', (socket) => {
  console.log('a user connected');
  socket.on('message', (msg) => {
    console.log(msg)
    socket.send(JSON.stringify({hey:'you'}))
  })
});

客户端连接-字符串:

代码语言:javascript
运行
复制
SOCKET_ENDPOINT = 'wss://******.azurewebsites.net/';

我已经在我的应用配置中打开了websockets。

编辑:

所以我现在已经把每一块石头。甚至将库从socket.io切换到了ws。同样的问题。当我尝试不同的东西时,我想我走得更远了,现在我得到了以下错误:"Firefox无法建立到wss://*.azurewebsites.net:8070/的服务器的连接。“

Edit2: http-upgrade很好

错误是这样的

编辑3: Curl命令:

代码语言:javascript
运行
复制
* TCP_NODELAY set
* Connected to *******.azurewebsites.net (20.40.202.6) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN, server did not agree to a protocol
* Server certificate:
*  subject: CN=*.azurewebsites.net
*  start date: Sep 28 19:00:01 2020 GMT
*  expire date: Sep 28 19:00:01 2021 GMT
*  subjectAltName: host "********.azurewebsites.net" matched cert's "*.azurewebsites.net"
*  issuer: C=US; O=Microsoft Corporation; CN=Microsoft RSA TLS CA 01
*  SSL certificate verify ok.
> GET /socket.io/?EIO=4 HTTP/1.1
> Host: *********.azurewebsites.net
> User-Agent: curl/7.68.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 401 Unauthorized
< Server: Kestrel
< WWW-Authenticate: Bearer realm="********.azurewebsites.net" authorization_uri="https://login.windows.net/<tenant>/oauth2/authorize" resource_id="<resource>"
< Date: Tue, 22 Jun 2021 05:56:15 GMT
< Content-Length: 0
< 
* Connection #0 to host *******.azurewebsites.net left intact
EN

Stack Overflow用户

发布于 2021-06-22 14:26:43

我猜您在Azure AppService中托管您的应用程序

确保在platform中打开了websocket选项:

AppService资源->设置->常规设置选项卡->平台设置部分

票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68031265

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档