2016-07-26 13 views
0

ich wie diese Proxy-Anfragen wollen: http://myproxy.com/api/folder1/result1?test=1
, http://myproxy.com/api/folder3447/something?var=oneNginx proxy_pass alle URL-Parameter

zu den entsprechenden Zielen: http://destination.com/folder1/result1?test=1 und http://destination.com/folder3447/something?var=one, praktisch nur die Domain-Änderungen und alle Unterordner und params werden beibehalten

Lage in Config wie folgt aussieht:

location ~* ^/api/(.*) { 
    proxy_pass http://destination.com/$1$is_args$args; 
    proxy_redirect off; 
    proxy_http_version 1.1; 
    proxy_set_header Connection ""; 
    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; 
    } 

Antwort

1

Sie sollten in der Lage Ihre Konfiguration leicht zu vereinfachen:

location /api/ { 
    // Note the slash at end, which with the above location block 
    // will replace "/api/" with "/". This will not work with regex 
    // locations 
    proxy_pass http://destination.com/; 
    proxy_redirect off; 
    proxy_http_version 1.1; 
    proxy_set_header Connection ""; 
    proxy_set_header X-Real-IP $remote_addr; 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
}