nginx配置http和ms转发

nginx配置http和ms共同转发,需要如下两步操作:

一.添加map配置映射表:

map $http_upgrade $connection_upgrade {
       default       keep-alive;
       'websocket'   upgrade; 
   }

如果只需要配置ms转发,则按照如下配置:

map $http_upgrade $connection_upgrade {
     default upgrade;
     ''      close;
}

二.proxy中添加proxy_set_header 等信息:

proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection  $connection_upgrade;

完整示例如下(同时支持http和ms):

# nginx.conf文件
http {
  map $http_upgrade $connection_upgrade {
       default       keep-alive;
       'websocket'   upgrade; 
  }
  server {
        listen       8081;
        server_name  localhost;
        root   html/dist;

        location / {
            root  /workspace/fontend/
        }
        location ~^(ms|api|test) {
		        proxy_pass http://127.0.0.1:8080
		        proxy_http_version 1.1;
		        proxy_set_header Upgrade $http_upgrade;
		        proxy_set_header Connection  $connection_upgrade;
        }
    }
}

猜你喜欢

转载自blog.csdn.net/weekdawn/article/details/129582574