简体   繁体   中英

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

I deployed a websocket server on an AWS EC2 instance. 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 .

I made sure to change the security group on the EC2 instance to allow all inbound and outbound traffic.

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.

This was a server-side issue with the gorilla/websocket package. Had to add this CheckOrigin function:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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