2016-12-12 9 views
0

Angesichts der folgenden nginx Konfiguration ...Wechsel zwischen Nginx-Konfigurationen (Profile)?

upstream myupstream { 
    server localhost:9000; 
} 

location ~ ^/.* { 
    root /path/to/var ; 
    try_files $uri $uri/ /index.html =404; 

    # proxy_pass http://myupstream; 
    # proxy_redirect  off; 
    ... 
} 

ich zwischen proxied spiegeln möchten und serviert (einen Knoten Server auf Port 9000 verwendet wird) (at/path/to/var) leicht ohne jeden Kommentar zu müssen Block. Gibt es ein Tool oder eine native Lösung, um zwischen verschiedenen nginx-Konfigurationen zu wechseln? (Eine Lösung würde erfordern nginx -s reload)

Antwort

0

Ok, versuchen Sie es. Fordern Sie /anyurl/?test=1 für den Wechsel zu Proxy, /anyurl/?test=0 für die Rückkehr auf lokale Festplatte.

root /path/to/var; 
error_page 464 = @proxy; 

location/{ 
    # check if test argument found in request 
    if ($arg_test ~ ^\d+$) { 
     # set cookie and redirect to same location 
     add_header Set-Cookie "test=$arg_test"; 
     return 302 $uri; 
    } 
    if ($cookie_test = "1") { 
     # cookie "test" found, redirect to named location via custom error code 
     # it can be any unused http code same as in error_page directive 
     return 464; 
    } 
    try_files $uri $uri/ /index.html =404; 
} 

location @proxy { 
    proxy_pass http://myupstream; 
} 
+0

Dies ist eine Problemumgehung. Ein nettes Workaround, das ich für Unikate verwenden könnte, aber diese Lösung erfordert die Änderung der URL. Ich versuche einen Weg zu finden, um die tatsächliche nginx-Konfiguration zu wechseln (erfordert ein nginx -s reload). – dook

+1

Hm ... es ist einfach zu lösen mit bash/bat-Skripten, die erforderlichen Teil der Konfiguration kopieren und nginx neu starten. –

Verwandte Themen