1

I'm new to nginx and I need to setup a reverse proxy. Most things are loading except for a few images.

my server is "bar:7081"

I have no control over foo:8088's webpage

Here's what I have:

location / {
    proxy_set_header Host $host;
    proxy_set_header Referer $http_referer;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_pass http://foo:8088/;
}

For lack of a better tool, I'm using chrome and firefox's f12 debugger...

When the page loads, I realize it's requesting this resource: http://bar:7081/api/proxy/get?url=http://foo:8088/images/image123.jpg

Of course, the client cannot access foo:8088, so I see a 502 bad gateway for: http://foo:8088/images/image123.jpg

Is there a way I can redirect the request? Thank you!

2
  • so you need to proxy_pass to the url that's on the querystring? (in this case foo:8088/images/image123.jpg) ?
    – flaixman
    Jul 11, 2019 at 6:05
  • Yes. I've also found it trying to request resources with the querystring foo:8077/images/image/456.jpg. If I can proxy_pass the url that would be great. I'm not sure if url rewrites will work in this case?
    – user531164
    Jul 11, 2019 at 16:57

1 Answer 1

0
location / {
    if ($arg_url) {
        proxy_pass $arg_url;
        proxy_set_header Host $host;
        proxy_set_header Referer $http_referer;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

Can you try this? You check the query string (?url=http://foo:8088/images/image123.jpg ) exists , then proxy pass to that argument of url .

https://nginx.org/en/docs/http/ngx_http_core_module.html#var_arg_

The $arg_name reads the argument of name= of the url

I know if are evil in nginx, but the alternative is also maping the querystring into a variable, and proxy_pass to the variable. (Lemme know if this doesn't do the trick and I'll try a maping config).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .