Reverse proxy - variable

Francis Daly francis at daoine.org
Tue Jan 15 21:58:35 UTC 2019


On Mon, Jan 14, 2019 at 05:50:19PM -0500, cboyke wrote:

Hi there,

> I've seen this asked and answered many times - and I've tried many of the
> suggestions posted, but still not able to get this to work.

The documentation for proxy_pass is at http://nginx.org/r/proxy_pass

That says how things are intended to work when a variable is used.

> I'm reverse-proxying to an internal IP inside an AWS VPC - eventually, I'd
> like to use a JavaScript function to give the correct IP, but for now I'm
> just hard-coding it in a variable.
> I've tried all of the below, and none work:

Can you show the "curl" command that you use to make the request of nginx,
and show the response?

It is often useful to use curl instead of a full browser, because it is
likely to show something other than "spins forever" -- it may fail to
respond, or it may show a http 301 to the same url, or something else.

> server {
>         listen 80;
>         server_name myserver.com;
>         location / {
>             set $with_trailing_slash "http://172.31.17.123:8080/";
>             #proxy_pass http://172.31.17.123:8080/;  #this works no
> problem.
>             #proxy_pass $with_trailing_slash;     # This gets to the
> upstream but gives a 404;

For what it's worth,

  proxy_pass http://127.0.0.1:8091;

and

  set $ip 127.0.0.1:8091;
  proxy_pass http://$ip;

work the same as each other for me, while

  proxy_pass http://127.0.0.1:8091/;

and

  set $ip 127.0.0.1:8091;
  proxy_pass http://$ip/;

do not work the same as each other -- the last bullet point in the
documentation explains why that is.

>             #proxy_pass $with_trailing_slash$request_uri;     # This spins
> forever
>             set $no_trailing_slash "http://172.31.17.123:8080";
>             #proxy_pass $no_trailing_slash; #spins forever;

Do you see a difference between using "proxy_pass $no_trailing_slash;"
and "proxy_pass http://172.31.17.123:8080"?

	f
-- 
Francis Daly        francis at daoine.org


More information about the nginx mailing list