WebSocket handshake: Unexpected response code: 400 nginx错误的解决方法

使用tornado + nginx + WebSocket 时出现 400 错误代码的解决方法

WebSocket handshake: Unexpected response code: 400

错误提示

1
WebSocket handshake: Unexpected response code: 400 nginx

解决方法

修改nginx 配置文件,如下例子

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
server {
    listen 80;
    root /home/chl/chat;
    index index.html index.htm;
 
    server_name _;
 
    location / {
        proxy_pass http://localhost:8080;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
    }
}

其中下面三行是重要的

1
2
3
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";

官方的配置 http://nginx.org/en/docs/http/websocket.html

本文网址: https://pylist.com/topic/132.html 转摘请注明来源

Suggested Topics

Tornado 搭建基于 WebSocket 的聊天服务

这年头 Python web 框架是有点泛滥了. 下面要介绍的是 facebook 的开源框架 tornado. 这东西比较简单, 而且自带 WebSocket 支持, 可以用它做个简单的聊天室. ...

在128M的VPS上配置mysql+Tornado+Nginx笔记

最近 123systems http://goo.gl/2Q0X2 又推出一年$10的便宜 VPS,128M内存,可以用来学习。在这样的vps 上放一个博客或做反向代理绰绰有余,买下后尝试配一个mysql+Tornado+Nginx 环境。...

tornado websocket 客户端与服务器端示例

最近在网上找了些websocket的资料看了下,node和tornado等等本身已经实现了websocket的封装,所以使用起来会比较简单,php如果想要写websocket还需要自己跑一整套流程,比较麻烦。...

Nginx 和 Golang web 上抢先体验 QUIC

QUIC(Quick UDP Internet Connection)是谷歌推出的一套基于 UDP 的传输协议,它实现了 TCP + HTTPS + HTTP/2 的功能,目的是保证可靠性的同时降低网络延迟。QUIC 是使用 UDP 协议,可以与原来的 TCP 服务不冲突。...

Leave a Comment