#自定義變量 $connection_upgrade
map $http_upgrade $connection_upgrade {
default keep-alive; #默認為keep-alive 可以支持 一般http請求
'websocket' upgrade; #如果為websocket 則為 upgrade 可升級的。
}
server {
...
location /chat/ {
proxy_pass http://backend;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade; #此處配置 上面定義的變量
proxy_set_header Connection $connection_upgrade;
}
}