我nginx
使用以下内容与我的 websocket 服务器一起工作:
server {
listen 80;
server_name streams.domain.com;
location / {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_pass http://192.168.1.52:80;
}
}
但是,我需要根据查询字符串参数更改目的地。我将其更改为以下内容:
server {
listen 80;
server_name streams.domain.com;
location / {
if ( $arg_serverId = 1562182 ) {
return 101 http://192.168.1.52:80;
}
}
}
现在我得到了错误Error during WebSocket handshake: 'Upgrade' header is missing
所以我尝试使用add_header
,但使用下面的配置我只是得到ERR_CONNECTION_TIMED_OUT
:
server {
listen 80;
server_name streams.domain.com;
location / {
if ( $arg_serverId = 1562182 ) {
add_header 'Upgrade' $http_upgrade;
add_header 'Connection' $connection_upgrade;
return 101 http://192.168.1.52:80;
}
}
}
那么如何使用$arg_
条件并传递 websocket 所需的升级标头?