proxying to upstream port based on scheme

Valentin V. Bartenev vbart at nginx.com
Wed Oct 5 15:32:58 UTC 2016


On Wednesday 05 October 2016 18:34:06 Anoop Alias wrote:
> I have an httpd upstream server that listen on both http and https at
> different port and want to send all http=>http_upstream and https =>
> https_upstream
> 
> The following does the trick
> 
> #####################
> if ( $scheme = https ) {
> set $port 4430;
> }
> if ( $scheme = http ) {
>         set $port 9999;
> }
> 
> location / {
> 
>     proxy_pass   $scheme://127.0.0.1:$port;
> }
> #####################
> 
> Just wanted to know if this is very inefficient (if-being evil) than
> hard-coding the port and having two different server{} blocks for http and
> https .
> 
[..]

Why don't use map?

  map $scheme $port {
      http  9999;
      https 4430;
  }


  proxy_pass   $scheme://127.0.0.1:$port;


 wbr, Valentin V. Bartenev



More information about the nginx mailing list