Reverse proxy - variable

Francis Daly francis at
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

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;
>         location / {
>             set $with_trailing_slash "";
>             #proxy_pass;  #this works no
> problem.
>             #proxy_pass $with_trailing_slash;     # This gets to the
> upstream but gives a 404;

For what it's worth,



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

work the same as each other for me, while



  set $ip;
  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 "";
>             #proxy_pass $no_trailing_slash; #spins forever;

Do you see a difference between using "proxy_pass $no_trailing_slash;"
and "proxy_pass"?

Francis Daly        francis at

More information about the nginx mailing list