简体   繁体   English

AWS Websocket服务器:从浏览器连接时发生403错误,从Python可以

[英]AWS websocket server: 403 error when connecting from browser, fine from Python

I deployed a websocket server on an AWS EC2 instance. 我在AWS EC2实例上部署了websocket服务器。 I am able to connect to this websocket without any issues from a Python script (using websocket.create_connection), but I get a 403 error when running the Javascript line var ws = new Websocket(.....) in Chrome: Error during WebSocket handshake: Unexpected response code: 403 . 我能够从Python脚本连接到此websocket,而没有任何问题(使用websocket.create_connection),但是在Chrome中运行Javascript行var ws = new Websocket(.....)时出现403错误:发生Error during WebSocket handshake: Unexpected response code: 403

I made sure to change the security group on the EC2 instance to allow all inbound and outbound traffic. 我确保更改EC2实例上的安全组,以允许所有入站和出站流量。

All suggestions appreciated! 所有建议表示赞赏!

EDIT: Figured out what was going on here. 编辑:弄清楚这里发生了什么。 It was an issue with the default origin check function in my Go websocket server. 我的Go websocket服务器中的默认来源检查功能存在问题。

This was a server-side issue with the gorilla/websocket package. 这是大猩猩/ websocket软件包的服务器端问题。 Had to add this CheckOrigin function: 必须添加此CheckOrigin函数:

var upgrader = websocket.Upgrader{
    ReadBufferSize: 1024,
    WriteBufferSize: 1024,
    CheckOrigin: func(r *http.Request) bool {return true},
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM