Bit of a 'fun' problem rather than something that's insurmountable in production, however I've been trying to find a way to expand variables inside other variables. For Example: In the following code block i'm setting an upstream variable on the back of an auth_request.
My auth_request uwsgi app will attempt multiple authentication methods, and depending on the availability of APIs, will redirect to one of many login applications if there's no current session. The specific login application URL is returned as the forward_to
header after the auth attempt, and then nginx will 302 to that URL.
I would like to provide nginx variables in that header such as $scheme://$host$uri
and have them expand with the redirect, however in the example, the redirect is to the literal string
https://example.com/login?referrer=$scheme://$host$uri
rather than for example expanded to
https://example.com/login?referrer=https://example.com/page
.
So, do you have any thoughts or ideas how to achieve this?
# Authenticate requests.
auth_request /auth/;
auth_request_set $forward_to $upstream_http_forward_to;
# forward_to set to https://example.com/login?referrer=$scheme://$host$uri string
error_page 401 =302 $forward_to; # Hope variables expand
# Authentication handler.
location /auth/ {
uwsgi_pass unix:/tmp/auth.sock;
include uwsgi_params;
uwsgi_param SCRIPT_NAME /auth;
}
Cheers!