V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
myyou
V2EX  ›  Python

使用 nginx 代理的 websocket 经常会出现消息延迟的现象,请问可能是什么原因?

  •  
  •   myyou · 2018-10-31 19:29:07 +08:00 · 2145 次点击
    这是一个创建于 2000 天前的主题,其中的信息可能已经有所发展或是发生改变。

    个人的 nginx 配置如下:

    upstream websocket {
        server 127.0.0.1:10300;
        server 127.0.0.1:10301;
        server 127.0.0.1:10302;
      }
    
    
    server {
        listen 80;
        client_max_body_size 4G;
        access_log /home/work/logs/nginx_access.log;
        error_log /home/work/logs/nginx_error.log;
        # 域名
        server_name www.example.com;
    
       add_header X-UA-Compatible "IE=edge,chrome=1"; # IE 用最新内核渲染页面
    
       location / {
            proxy_pass http://websocket;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "Upgrade";
    
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_set_header X-NginX-Proxy true;
            proxy_redirect default;
            add_header "Access-Control-Allow-Origin" "*";
            add_header "Access-Control-Allow-Credentials" "true";
            add_header "Access-Control-Allow-Headers" "X-Requested-With";
            }
      }
    
    
    1 条回复    2018-11-01 05:00:40 +08:00
    tz1006
        1
    tz1006  
       2018-11-01 05:00:40 +08:00
    对 Nginx 不精通,
    两个建议
    1. 有可能是缓存, 配置文件还有从别的地方导入的,你上面没贴出缓存相关的配置。
    2. 尝试使用最新版本或者稳定版本的 Nginx。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5368 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 07:46 · PVG 15:46 · LAX 00:46 · JFK 03:46
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.