没有合适的资源?快使用搜索试试~ 我知道了~
在Nginx反向代理一个带有WebSocket功能的Spring Web程序(源代码地址 )时,发现访问WebSocket接口时总是出现403响应,Nginx的配置参考的是 官方文档 : http { // ssl 相关配置 ... map $http_upgrade $connection_upgrade { default upgrade; '' close; } server { listen 8020; location /ws { proxy_pass http://some-ip:8080; proxy_ht
资源推荐
资源详情
资源评论
详解详解Nginx反向代理反向代理WebSocket响应响应403的解决办法的解决办法
在Nginx反向代理一个带有WebSocket功能的Spring Web程序(源代码地址 )时,发现访问WebSocket接口时总是出现403响
应,Nginx的配置参考的是 官方文档 :
http {
// ssl 相关配置 ...
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 8020;
location /ws {
proxy_pass http://some-ip:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}
}
唯一不同的是我们的Nginx配置了https。
于是打开Spring日志查看直接访问和通过Nginx访问的差别。
直接访问的日志:
DEBUG ... o.s.web.servlet.DispatcherServlet : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/ws/gs-guide-
websocket/786/kz0qai5l/websocket] DEBUG ... s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /gs-guide-
websocket/786/kz0qai5l/websocket
DEBUG ... s.w.s.m.m.a.RequestMappingHandlerMapping : Did not find handler method for [/gs-guide-websocket/786/kz0qai5l/websocket] DEBUG ...
o.s.w.s.s.s.WebSocketHandlerMapping : Matching patterns for request [/gs-guide-websocket/786/kz0qai5l/websocket] are [/gs-guide-websocket/**]
DEBUG ... o.s.w.s.s.s.WebSocketHandlerMapping : URI Template variables for request [/gs-guide-websocket/786/kz0qai5l/websocket] are {}
DEBUG ... o.s.w.s.s.s.WebSocketHandlerMapping : Mapping [/gs-guide-websocket/786/kz0qai5l/websocket] to HandlerExecutionChain with handler
[org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler@307f6b8c] and 1 interceptor
DEBUG ... o.s.web.servlet.DispatcherServlet : Last-Modified value for [/ws/gs-guide-websocket/786/kz0qai5l/websocket] is: -1
DEBUG ... o.s.web.cors.DefaultCorsProcessor : Skip CORS processing: request is from same origin
DEBUG ... o.s.w.s.s.t.h.DefaultSockJsService : Processing transport request: GET http://localhost:8080/ws/gs-guide-websocket/786/kz0qai5l/websocket
DEBUG ... o.s.web.servlet.DispatcherServlet : Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming
HandlerAdapter completed request handling
DEBUG ... o.s.web.servlet.DispatcherServlet : Successfully completed request
通过Nginx访问的日志:
DEBUG ... o.s.web.servlet.DispatcherServlet : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/ws/gs-guide-
websocket/297/jp1c3ab5/websocket] DEBUG ... s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /gs-guide-
websocket/297/jp1c3ab5/websocket
DEBUG ... s.w.s.m.m.a.RequestMappingHandlerMapping : Did not find handler method for [/gs-guide-websocket/297/jp1c3ab5/websocket] DEBUG ...
o.s.w.s.s.s.WebSocketHandlerMapping : Matching patterns for request [/gs-guide-websocket/297/jp1c3ab5/websocket] are [/gs-guide-websocket/**]
DEBUG ... o.s.w.s.s.s.WebSocketHandlerMapping : URI Template variables for request [/gs-guide-websocket/297/jp1c3ab5/websocket] are {}
DEBUG ... o.s.w.s.s.s.WebSocketHandlerMapping : Mapping [/gs-guide-websocket/297/jp1c3ab5/websocket] to HandlerExecutionChain with handler
[org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler@307f6b8c] and 1 interceptor
DEBUG ... o.s.web.servlet.DispatcherServlet : Last-Modified value for [/ws/gs-guide-websocket/297/jp1c3ab5/websocket] is: -1
DEBUG ... o.s.w.s.s.t.h.DefaultSockJsService : Processing transport request: GET http://localhost:8080/ws/gs-guide-websocket/297/jp1c3ab5/websocket
DEBUG ... o.s.w.s.s.s.OriginHandshakeInterceptor : Handshake request rejected, Origin header value https://some-host.com not allowed
DEBUG ... o.s.w.s.s.s.HandshakeInterceptorChain : org.springframework.web.socket.server.support.OriginHandshakeInterceptor@25ce6ad4 returns
false from beforeHandshake - precluding handshake
DEBUG ... o.s.web.servlet.DispatcherServlet : Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming
HandlerAdapter completed request handling
DEBUG ... o.s.web.servlet.DispatcherServlet : Successfully completed request
注意到直接访问的日志里有这么一条:
代码如下:
DEBUG … o.s.web.cors.DefaultCorsProcessor : Skip CORS processing: request is from same origin
通过Nginx访问的日志里有这么一条:
代码如下:
资源评论
weixin_38661650
- 粉丝: 7
- 资源: 928
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Qu120钢轨的CO2气体保护焊焊接.pdf
- RCC-M2007版与2000版+2002补遗对核级设备焊接过程中热输入要求及差异分析 - .pdf
- QXL锅炉连梁焊接变形的控制与火焰矫正 - .pdf
- RMD焊接工艺隧道管道安装中质量的防控措施.pdf
- RCC-M中的焊接材料评定.pdf
- S31803双相不锈钢球罐制造及焊接技术 - .pdf
- S31803双相不锈钢对接接头焊接工艺参数研究.pdf
- S30408等离子焊接接头组织与性能分析 - .pdf
- S450EW新型耐候钢焊接工艺与低温韧性研究 - .pdf
- S30408不锈钢活性焊接接头微观组织及性能研究.pdf
- S31008(06Cr25Ni20)耐热不锈钢的焊接工艺.pdf
- SA203 Cr.E 的气体容器的焊接工艺评定.pdf
- SA203Gr.D低温钢多道焊焊接性能试验研究.pdf
- SA213-T9合金耐热钢焊接技术.pdf
- SA-204Gr.C的焊接性能与金相组织.pdf
- SA-213T12换热管与SA-387Gr.11CL2管板内孔对接焊接工艺研究.pdf
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功