您当前的位置: 首页 >  websocket

mutourend

暂无认证

  • 3浏览

    0关注

    661博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

nginx 代理websocket问题排查

mutourend 发布时间:2019-08-23 11:04:18 ,浏览量:3

1. 使用curl测试websocket服务是否能正常连入

可根据参考资料[1][2]中的内容来完成,对于https连接:

curl --include --no-buffer --header "Connection: Upgrade" --header "Upgrade: websocket"  --header "Host: xxx.xxx.com"  --header "Origin: https://xxx.xxx.com"  --header "Sec-WebSocket-Key: SGVsbG8sIHdvcmxkIQ=="  --header "Sec-WebSocket-Version: 13" https://xxx.xxx.com/pushsrv

若可正常连接,可返回如下信息: 在这里插入图片描述 在这里插入图片描述 若不正常,则有如下信息返回: 在这里插入图片描述 且不后台也有如下报错信息:在这里插入图片描述

2. 通过nginx反向代理websocket问题分析

实际是通过nginx反向代理了websocket连接,参照参考资料[3],需在nginx中的default.conf中增加如下配置信息:

proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
3. nginx代理的情况分析

可在nginx.conf中增加log信息分析:

log_format  main  '$time_iso8601 $http_x_forwarded_for $remote_addr "$request" $status $content_length $content_type $request_body $body_bytes_sent "$http_referer" "$http_user_agent" "$proxy_add_x_forwarded_for" @@"$http_accept_encoding"';

default.conf中对应配置与上面main相应的名称。 在这里插入图片描述

参考资料: [1] https://blog.csdn.net/sd2131512/article/details/74996577 [2] https://gist.github.com/htp/fbce19069187ec1cc486b594104f01d0 [3] http://nginx.org/en/docs/http/websocket.html

关注
打赏
1664532908
查看更多评论
立即登录/注册

微信扫码登录

0.0391s