can variables be used in regular expressions?

foxgab nginx-forum at
Thu Jul 27 07:55:40 UTC 2017

i want to change the redirect location URI protocol to https if that is
using, so i tried to configure like this:

  proxy_redirect      ~*^http://$host(/.*)?$ $scheme://$host$1;

but that didn't work, so i change it to:

  proxy_redirect      http://$http_host $scheme://$http_host;

then, it works. I suspect that the variable in regular expressions is treat
as a string, hence my former directive failed, am I right?
Is there any way to make variables effect in regular expressions?

Posted at Nginx Forum:,275675,275675#msg-275675

More information about the nginx mailing list