nginx 同时反向代理 websocket 和 http

技术分享 2022-06-06 15:53:58
#PROXY-START/peerjs/

location ^~ /peerjs/
{
    proxy_pass https://0.peerjs.com/;
    proxy_set_header Host 0.peerjs.com;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE-HOST $remote_addr;
    proxy_set_header Upgrade $http_upgrade;  
    proxy_set_header Connection "Upgrade"; 

    add_header X-Cache $upstream_cache_status;

    #Set Nginx Cache
    
    
    set $static_fileFYdmcVJi 0;
    if ( $uri ~* "\.(gif|png|jpg|css|js|woff|woff2)$" )
    {
    	set $static_fileFYdmcVJi 1;
    	expires 12h;
        }
    if ( $static_fileFYdmcVJi = 0 )
    {
    add_header Cache-Control no-cache;
    }
}

#PROXY-END/peerjs/

现在很多web应用一个地址,同时支持http和websocket的协议连接


这两句主要websocket

proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade";
咨询小瓶科技
咨询我们
顶部