{{tag>nginx "query parameter" redirect proxy}} ====== 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 ====== * nginx/1.21.4 ====== See also ====== * [[Nginx redirect/rewrites]] ====== References ====== * https://stackoverflow.com/questions/57937222/502-bad-gateway-nginx-no-resolver-defined-to-resolve * https://stackoverflow.com/questions/8130692/how-can-query-string-parameters-be-forwarded-through-a-proxy-pass-with-nginx