Welcome! Log In Create A New Profile

Advanced

Help: Proxy_pass with map variables!

Posted by gocleaver 
Help: Proxy_pass with map variables!
December 12, 2013 09:53AM
Hi, I have scoured all documentation and dozens of similar examples I can find on google, but cannot make this work...

I would like to know if its possible to use map variables with proxy_pass. I have setup an NGINX server to be used as a remote proxy with rewrite rules. Depending on the $uri provided, I wish to redirect to a certain upstream server. However I cannot make it work. I have defined upstream servers, as well as a map. Ive tested that the upstream server name works, and also that the variable mapping works as well. But proxy_pass does not seem to 'read' the mapped variable, even if i use IP isntead of hostname... by the way, the IPs I am using are local, as the backend servers are not visible to internet, only through reverse proxy. My config looks something like this:

-------------------------------------------
## T-US-WA-2 backend for test.blahblah.com
upstream t-us-wa-2 {
server 10.10.1.12:80; #t-us-wa-2.blahblah.com
}
## T-US-Webapps-2 backend for test.blahblah.com
upstream t-us-webapps-2 {
server 10.10.1.203:80; #t-us-webapps-2.blahblah.com
}


# URI to Server Map
map $1 $upstream_host {
test-t-us-wa-2 t-us-wa-2;
new3 t-us-webapps-2;

}

server {
location ~ ^/(.*)$ {
resolver 127.0.0.1;
rewrite ^/([^/]+)$ https://test.blahblah.com=$1#login last;
proxy_pass http://$1;
#proxy_pass http://t-us-wa-2; #if uncommented, this line will allow the following to work:
# https://test.blahblah.com=test-t-us-wa2#login
}
}
------------------

I would be VERY grateful if someone could point out my mistake. Thanks!
Re: Help: Proxy_pass with map variables!
December 12, 2013 12:04PM
ARGH this forum seems to be down constantly....I made a couple mistakes in the original post, but when I tried to go back to edit, the site was unavailable...so here is the revision:

Hi, I have scoured all documentation and dozens of similar examples I can find on google, but cannot make this work...

I would like to know if its possible to use map variables with proxy_pass. I have setup an NGINX server to be used as a remote proxy with rewrite rules. Depending on the $uri provided, I wish to redirect to a certain upstream server. However I cannot make it work. I have defined upstream servers, as well as a map. Ive tested that the upstream server name works, and also that the variable mapping works as well. But proxy_pass does not seem to 'read' the mapped variable, even if i use IP isntead of hostname... by the way, the IPs I am using are local, as the backend servers are not visible to internet, only through reverse proxy. DNSMASQ is running on this server, so 127.0.0.1 *should* work, but doesnt doesnt, even if I specify an alternate DNS server. My config looks something like this:

-------------------------------------------
## T-US-WA-2 backend for test.blahblah.com
upstream t-us-wa-2 {
server 10.10.1.12:80; #t-us-wa-2.blahblah.com
}
## T-US-Webapps-2 backend for test.blahblah.com
upstream t-us-webapps-2 {
server 10.10.1.203:80; #t-us-webapps-2.blahblah.com
}


# URI to Server Map
map $1 $upstream_host {
test-t-us-wa-2 t-us-wa-2;
new3 t-us-webapps-2;

}

server {
location ~ ^/(.*)$ {
resolver 127.0.0.1;
rewrite ^/([^/]+)$ https://test.blahblah.com=$1#login last;
proxy_pass http://$upstream_host;
#proxy_pass http://t-us-wa-2; #if uncommented, this line will allow the following to work:
# https://test.blahblah.com=test-t-us-wa2#login
}
}
------------------

I would be VERY grateful if someone could point out my mistake. Thanks!
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 345
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready