nginx 整合 springcloud-gateway网关转发websocket请求

第一步:配置nginx配置文件,支持转发websocket请求

主要在location配置端增加以下配置项

         proxy_http_version 1.1;
		 proxy_set_header Upgrade $http_upgrade;
		 proxy_set_header Connection "upgrade";

完整location配置如下:

http://api-gateway:9090,为网关服务地址

location /data-development/ {
         proxy_pass http://api-gateway:9090;
         proxy_set_header   X-Real-IP        $remote_addr;
         proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
		 proxy_http_version 1.1;
		 proxy_set_header Upgrade $http_upgrade;
		 proxy_set_header Connection "upgrade";
      }

 

nginx 整合 springcloud-gateway网关转发websocket请求_第1张图片

 

第二步:api-gateway网关增加转发websocket请求

(其中一段配置转发wobsocket请求,另外一段配置转发http请求)

在route路由属性配置下,增加以下配置
- id: data-development-web-websocket #  data-development-websocket服务路由
  uri: lb:ws://data-development-web
  order: 1
  predicates:
    - Path=/data-development/ws/**
- id: data-development-web #  data-development服务路由
  uri: lb://data-development-web # websocket所在的服务
  order: 2
  predicates:  
    - Path=/data-development/**

nginx 整合 springcloud-gateway网关转发websocket请求_第2张图片

 

然后重启网关,再重启nginx即可。 

 

解释:

其中

第一步的配置是解决nginx转发websocket请求

第二步的配置是解决springcloud-gateway转发websocket请求

 

 

你可能感兴趣的:(java,springcloud,nginx,网关)