2014-09-12 161 views
1

在我的應用程序中,基於cookie,我必須將請求轉發到某個apache端口。我想是這樣的:替代else運算符和不等於nginx運算符

server { 
    listen  80; 
    server_name example.com; 
    location/
    { 
     proxy_set_header X-Real-IP $remote_addr; 
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
     proxy_set_header Host $http_host; 
     proxy_set_header X-FORWARDED_PROTO https; 
     if ($http_cookie ~ 'ver=1') { 
      proxy_pass http://127.0.0.1:6060; 
     } 
     else { 
      proxy_pass http://127.0.0.1:7070; 
     } 
    } 
} 

爲「其他」,而不是在nginx.conf允許,我能爲這種類型的要求完成「〜!」?

回答

4

分配一個變量和使用這樣的:

server { 
    listen  80; 
    server_name ver.jeevansathi.com; 
    location/
    { 
     proxy_set_header X-Real-IP $remote_addr; 
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
     proxy_set_header Host $http_host; 
     proxy_set_header X-FORWARDED_PROTO https; 
     set $cookie_redirect 0; 
     if ($http_cookie ~ 'ver=1') { 
      set $cookie_redirect 1; 
     } 
     if ($cookie_redirect ~ 1) { 
      proxy_pass http://127.0.0.1:6060; 
     } 
     if ($cookie_redirect ~ 0) { 
      proxy_pass http://127.0.0.1:7070; 
     } 
    } 
}