【问题标题】:How do I setup my nginx configuration file to allow websocket connections via Tornado?如何设置我的 nginx 配置文件以允许通过 Tornado 进行 websocket 连接?
【发布时间】:2013-07-12 16:24:21
【问题描述】:

我在使用 nginx 作为反向代理向 Tornado 提供 websocket 连接时遇到问题。 websocket 连接在没有 nginx 的情况下工作正常(直接馈送到 Tornado),并且最新版本的 nginx 应该支持 websockets,所以我的配置文件中一定有错误......错误(来自最新的前沿 Chrome beta)是:

Error during WebSocket handshake: 'Connection' header value is not 'Upgrade'

以下是我的 nginx.conf 文件中的相关位:

location / {
    proxy_pass_header Server;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Scheme $scheme;
    proxy_pass http://tornadoes;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
}

【问题讨论】:

  • 你的 nginx 是哪个版本的? Websocket 仅适用于 1.4 版本>nginx.org/en/docs/http/websocket.html
  • 谢谢,我查了一下,没有意识到最新版本的Ubuntu默认使用的是旧版本的nginx!我按照这里的说明进行了升级:bit.ly/1azyPDO

标签: nginx websocket tornado


【解决方案1】:

显然你需要在 Ubuntu 上强制升级 nginx:

sudo apt-get install python-software-properties
sudo apt-get install software-properties-common

sudo add-apt-repository ppa:nginx/stable
sudo apt-get update
sudo apt-get upgrade nginx

service nginx status

【讨论】:

    猜你喜欢
    • 2014-04-17
    • 2023-04-03
    • 1970-01-01
    • 2015-12-02
    • 2020-07-09
    • 2020-11-16
    • 2020-11-01
    • 2017-06-01
    • 1970-01-01
    相关资源
    最近更新 更多