I don't think browsers actually allow this. I think it could cause a lot of compatibility and security issues if pages could arbitrarily change the browser user agent.
If you want to specify some extra data to handle on the server side, usually you'd do that with query string parameters or POST data.
Changing the name in the userAgent is a common practice, for example, almost all bots use it.
Then you can configure the rules on the nginx server itself.