0

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!

TechnicalChaos
  • 133
  • 1
  • 8
  • Probably you could do it with Lua, but actually why don't just «expand» them in your app? – Alexey Ten Sep 06 '17 at 08:48
  • I've never bothered using Lua scripts yet. I'm not sure the Lua module is compiled into nginx across all hosts that this could be used on, but i'll do some reading. Thanks! As to why not expand in the app - I can do which is fine, this is just really a proof of concept problem to illustrate the issue. As I say it's more 'can this be done' rather than 'I need this' – TechnicalChaos Sep 06 '17 at 08:51

0 Answers0