Nginx 支持webSocket 响应403

web项目为了解决并发连接数,并发现在数,下载流量问题,我在我们项目引入了nginx。最近项目加入websocket协议,集成推送功能。突然发现,nginx代理不了了,响应403.

网上找了些列子,包括官网http://nginx.org/en/docs/http/websocket.html  给出的配置内容:

location /chat/ {
    proxy_pass http://backend;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
}

然而并没有什么卵用。配置完后错误还是没有解决。最终费了好大力气。找到解决方法:

 # Pass the csrf token (see https://de.wikipedia.org/wiki/Cross-Site-Request-Forgery)
    # Default in Spring Boot and required. Without it nginx suppresses the value
    proxy_pass_header X-XSRF-TOKEN;

    # Set origin to the real instance, otherwise a of Spring security check will fail
    # Same value as defined in proxy_pass
    proxy_set_header Origin "http://testsysten:8080"; 

添加以上两句就ok了。原因(自行翻译):

Nginx needs to pass some additional header values if you want to use Websocket and Spring Security. The following lines need to be added to locationsection in your Nginx config。

 

转载于:https://my.oschina.net/wrs/blog/727313

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值