今天配置nginx反向代理,按照官方提供的方法配置后
配置:
-
http {
-
map $http_upgrade $connection_upgrade {
-
default upgrade;
-
'' close;
-
}
-
-
server {
-
...
-
-
location /websocket/ {
-
proxy_pass http://backend;
-
proxy_http_version 1.1;
-
proxy_set_header Upgrade $http_upgrade;
-
proxy_set_header Connection $connection_upgrade;
-
}
-
}
出现 403错误
-
WebSocket connection to 'ws://ip/websocket/aa' failed: Error during WebSocket handshake:Unexpected response code:403
解决方法:
添加以下命令:
-
# 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 ""
参考:
https://my.oschina.net/wrs/blog/727313
阅读(1296) | 评论(0) | 转发(0) |