Table of Contents

, , ,

Redirect to another site from query parameter in nginx

If you have an URL for example:

https://sub.domain.com/some_image?src=https://www.someotherdomain.com/file/thumbnail/blahblah/43433/image.jpg

You can do a redirect to a URL in the src parameter by using below in nginx when visiting above URL.

     location /some_image {
            proxy_pass $arg_src;
            proxy_set_header Host $host;
            resolver 127.0.0.11;
        }

Below could also work (not tested):

location @fetchFromRemote {
        rewrite ^/some_image(.*)$ $arg_src redirect;
    }
 
location ^~ /some_image {
        try_files $arg_src @fetchFromRemote;
    }

Tested on

See also

References