I have an nginx config that let's me proxy an arbitrary URL through it. For example:
https://proxy.example.com/?address=http://anywhere.net/path/to/file
This configuration works (except redirects don't maintain the proxy's URL):
server {
server_name proxy.example.com;
listen 80;
resolver 1.1.1.1;
location / {
proxy_intercept_errors on;
error_page 301 302 307 = @handle_redirects;
if ($arg_address != "") {
proxy_pass $arg_address;
}
}
location @handle_redirects {
set $orig_loc $upstream_http_location;
proxy_pass $orig_loc;
}
}
Unfortunately, what I actually need is a way to specify the target domain + path in the request path, like this:
https://proxy.example.com/anywhere.net/path/to/file
This would essentially serve up the content from http://anywhere.net/path/to/file
(the target will always be HTTP).
I'm under the impression nginx may not be able to do this, as I've tried a number of various configs without success (not worth posting since none actually worked).
My use case for this is an app that runs over HTTPS, but has to display user websites that are sometimes only available via HTTP. This is a proxy that will prevent mixed content from being blocked in a very controlled environment.
Any pointers on how to proxy an arbitrary domain + path through the request path? (Following redirects without changing the URL is a bonus.)
Maybe you want to check the config from here. This seems to do what you want: