2017-10-30 9 views
0
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"을 (대소 문자 무시)으로 변경하고 싶습니다. 어떻게 할 수 있습니까? 나는 나 자신을 몇 가지 시도했다. 유사 :상태가 nginx conf의 위치 블록 내부에서 작동하는 경우 어떻게됩니까?

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

이 같은 시도하십시오 :

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; 
}