nginx代理webSocket 和eventSource 相关配置

发布时间 2023-06-06 18:04:33作者: fy_qxl

文章转载自: https://blog.csdn.net/Embrace924/article/details/92649471

nginx代理webSocket 和eventSource 请求超时连接不通 但是本地可以
nginx代理出了问题 不能普通代理一样
要先发起普通请求代理 然后通过一些属性再次转换


#常用配置
location /api/ {
        proxy_pass http://请求地址/;
}


#eventSource
location /es/ {
      proxy_pass http://请求地址/;
      proxy_set_header Connection '';
      proxy_http_version 1.1;
      chunked_transfer_encoding off;
      proxy_buffering off;
      proxy_cache off;
}

 

#webSocket
location /api/ws/ {
       proxy_pass http://请求地址/;
       proxy_redirect off;
       proxy_http_version 1.1;
       proxy_set_header Upgrade $http_upgrade;
       proxy_set_header Connection "upgrade";
}