V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
liuyinltemp
V2EX  ›  NGINX

请教大佬, nginx 反代时候是不是用 websocket 性能更好?

  •  
  •   liuyinltemp · 2023-04-02 21:58:07 +08:00 · 2330 次点击
    这是一个创建于 391 天前的主题,其中的信息可能已经有所发展或是发生改变。

    使用 websocket:

    server { listen 443 ssl http2; ............

     		   }
    
    location / {
               ............
     		proxy_http_version 1.1;
     		proxy_set_header Upgrade $http_upgrade;
     		proxy_set_header Connection "upgrade";
     		   }
               .........
     		}
    

    使用 http 1.1

    server { listen 443 ssl http2; ............

     		   }
    
    location / {
               ............
     		proxy_http_version 1.1;
     		proxy_set_header Connection "";
     		   }
               .........
     		}
    

    上面两种应该都对吧?是不是第一张反代时候访问用 websocketgeng'h 更好,1M 小水管想尽可能快一点。

    9 条回复    2023-05-28 18:33:28 +08:00
    thinkershare
        1
    thinkershare  
       2023-04-02 22:06:09 +08:00
    是使用 Web Socket 时候必须使用第一种方式,第二种用 Web Socket 连接会失败的。
    liuyinltemp
        2
    liuyinltemp  
    OP
       2023-04-02 22:20:03 +08:00
    @thinkershare 就是简单反代,性能上有区别吗?
    richangfan
        3
    richangfan  
       2023-04-02 22:49:59 +08:00
    http 和 websocket 数据报文都不一样,不兼容的
    star7th
        4
    star7th  
       2023-04-02 22:58:31 +08:00
    如果你想大量转发什么数据,确实使用 websocket 协议性能更好
    star7th
        5
    star7th  
       2023-04-02 22:58:59 +08:00
    但是 1M 的带宽,物理上限就在那里了,再怎么折腾都不会差多少。
    des
        6
    des  
       2023-04-02 23:09:42 +08:00 via iPhone
    如果我没记错的 websocket 和 h2 不兼容。另外不知道你要做什么,总感觉你这么对比有点怪
    ryd994
        7
    ryd994  
       2023-04-02 23:16:20 +08:00 via Android
    websocket 不是 http 的平行代替,更不是 http 的承载载体
    而是 websocket 让 http 可以双向传输数据。或者说 http 是 websocket 的载体

    即使是 1 的情况,如果网站本身没有用到 ws ,那结果和 2 是一样的
    liuyinltemp
        8
    liuyinltemp  
    OP
       2023-04-03 09:22:51 +08:00
    @ryd994 源站没有 websocket ,那确实没啥意义
    gotosre
        9
    gotosre  
       335 天前
    不同的, 取决于 upstream 是啥协议啊
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2514 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 16:01 · PVG 00:01 · LAX 09:01 · JFK 12:01
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.