2

I am trying to manipulate an nginx variable.

I have a variable names $user which contains a UPN like [email protected] I want to set another variable, $xuser; to be the $user minus the @domain - ie, someone.

This is done in a location block, so I don't think that I can use map.

I have tried this, but $xuser never seems to get set:

if ($user ~* "(?<p>[aa-zZ]+)@example.com")
{
        set $xuser $p;
}

1 Answer 1

5

You can use map in 'http' block.

http://nginx.org/en/docs/http/ngx_http_map_module.html

map $user $xuser {
  ~^(\w+)@example.com $1;
  default '';
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I had to convert that into a named match parameter, otherwise it threw an error regarding $1 being undefined

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.