nginx 反代 websocket,为什么被代理端写入错误 write: broken pipe ? - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
请不要在回答技术问题时复制粘贴 AI 生成的内容
voidmnwzp

nginx 反代 websocket,为什么被代理端写入错误 write: broken pipe ?

  •  
  •   voidmnwzp
    NullpointerW Sep 10, 2024 2662 views
    This topic created in 596 days ago, the information mentioned may be changed or developed.

    客户端能与 nginx 握手成功,但接收不到数据,难道是 nginx 这边关闭了被代理端连接? 搞了快一天,Google 也搜不到,使劲浑身解数还是没辙,

    upstream target { server xxx.xxx.xxx.xxx:8080; } location /wss { proxy_pass http://target/ws; proxy_http_version 1.1; proxy_set_header Upgrade websocket; proxy_set_header Connection "Upgrade"; proxy_redirect off; proxy_cache_bypass $http_upgrade; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_buffering off; proxy_set_header X-Forwarded-Host $server_name; proxy_set_header Access-Control-Allow-Origin *; proxy_set_header X-NginX-Proxy true; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; gzip off; proxy_set_header X-Forwarded-Ssl on; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Frame-Options SAMEORIGIN; proxy_read_timeout 5d; proxy_send_timeout 5d; proxy_connect_timeout 5d; send_timeout 5ds; fastcgi_connect_timeout 5d; fastcgi_read_timeout 5d; fastcgi_send_timeout 5d; } 

    然后 golang 这边服务端写入时的错误为

    ws written err: write tcp xxx:8080->xxx:53376: write: broken pipe 
    5 replies    2024-09-11 15:03:28 +08:00
    log4j
        1
    log4j  
       Sep 10, 2024
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    我这边只加了这 3 个就可以了。其余的没加
    nextvay
        2
    nextvay  
       Sep 10, 2024
    golang 这边的问题吧,链接断了
    montaro2017
        3
    montaro2017  
       Sep 11, 2024
    之前我是这样配的
    ```
    location /ws/ {
    proxy_pass http://127.0.0.1:8100/;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
    }
    ```
    voidmnwzp
        4
    voidmnwzp  
    OP
       Sep 11, 2024
    @montaro2017 试过了 没用 如果关闭 buffer 会提示 broken pipe ,不关闭的话会在上游的连接断开后 nginx 才会和客户端建立连接
    montaro2017
        5
    montaro2017  
       Sep 11, 2024
    @voidmnwzp #4 那我感觉就不像是 nginx 配置问题了
    About     Help     Advertise     Blog     API     FAQ     Solana     992 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 41ms UTC 22:22 PVG 06:22 LAX 15:22 JFK 18:22
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86