Nginx proxy_redirect allows the use of variables such as $my_var and regular expressions, prefixed with ~.
But it seems impossible to use them both in combination. Is this possible, and what is the correct syntax for escaping meta-characters?
For example, I've tried:
proxy_redirect ~*https?://\\$proxy_host/(.*)$ /app1/$1
proxy_redirect ~*https?://\$proxy_host/(.*)$ /app1/$1
proxy_redirect ~*https?://$proxy_host/(.*)$ /app1/$1
Obviously the last example is incorrect, as the $ before proxy_host is interpreted as a regex meta character. But the two other examples don't work either. (They aren't recognized and so don't rewrite the Location header.
When I replace with just
proxy_redirect ~*https?://[^/]+/(.*)$ /app1/$1
the redirect works just fine.
The issue is that this will redirect even for external redirects, so is too inclusive.