location /x/ {
limit_conn x 500;
add_header Access-Control-Allow-Origin *;
allow all;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
chunked_transfer_encoding off;
proxy_buffering off;
proxy_cache off;
proxy_read_timeout 2073600;
if ($http_upgrade = websocket) {
proxy_pass http://x;
}
if ($http_upgrade != websocket) {
proxy_pass http://y;
}
}
在这里,我想制作" websocket" 不区分大小写(忽略大小写)。如何制作?我自己尝试过一些东西。像:
1.
if ($http_upgrade = ~*websocket) {
proxy_pass http://x;
}
if ($http_upgrade != ~*websocket) {
proxy_pass http://y;
}
2.
if ($http_upgrade = "(?i) websocket") {
proxy_pass http://x;
}
if ($http_upgrade != "(?i) websocket") {
proxy_pass http://y;
}
但两种情况都不起作用。
答案 0 :(得分:1)
请尝试这些:
if ($http_upgrade == "websocket")
{
proxy_pass http://x;
}
if ($http_upgrade != "websocket")
{
proxy_pass http://y;
}
或强>
if ($http_upgrade == "websocket")
{
proxy_pass http://x;
}
else
{
proxy_pass http://y;
}