Welcome! Log In Create A New Profile

Advanced

proxy_pass, dynamic ports upstream

November 15, 2012 11:43AM
I have a requirement to be able to map a portion of a request URI to a port on a set of upstream servers. I'm hoping nginx will be able to solve this for me, but so far no luck.

Request:
http://example.com/2201/reg/106903/0?something=here&somemore=stuff

Needs to be proxied to:
http://10.11.12.13:2201/reg/106903/0?something=here&somemore=stuff

So the 1st portion of the URI is used as the upstreams port. However I'm having difficulty with this when I attempt to combine it with a set of upstream servers. The below configuration results in the error "no resolver defined to resolve engines".

If I specify the upstream as " proxy_pass http://10.11.12.13:$1/$2/?$args; " (and change nothing else) the below configuration works... however it's not being load balanced obviously.

Basically, can I load balance and use dynamic ports?


Configuration:

upstream engines {
server 10.11.12.13;
server 10.11.12.14;
}

server {
listen *:80;

access_log /var/log/nginx/engines.access.log main;
error_log /var/log/nginx/engines.error.log debug;

location ~/([0-9]*)/ {
rewrite ^/([0-9]*)/(.*)$ $2 break;
proxy_pass http://engines:$1/$2/?$args;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_redirect off;
proxy_buffering on;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Subject Author Posted

proxy_pass, dynamic ports upstream

mahhy November 15, 2012 11:43AM

Re: proxy_pass, dynamic ports upstream

Jonathan Matthews November 15, 2012 12:26PM

Re: proxy_pass, dynamic ports upstream

mahhy November 15, 2012 02:33PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 108
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready