According the official documentation, the only way to manipulate environment variables in nginx is through the use of the env
directive, only available in the main
context (ie not dependent on the protocol such as http
, thus not its inherent server
s).
That means, the variables will be set for the whole nginx environment (even though it seems you can change it worker-based, which are independant processes).
To do what you wish, I would suggest either:
- Use separate nginx instances for each subdomain, reading the common configuration parts from the same files (so you do not have to maintain separate copies of the main trunk) and the set the environment of each nginx instance according to the specific subdomain it serves
- Follow @XavierLucas's proposal and use some modules such as the embedded perl or the third-party Lua ones