Check if variable exists in file, Using file contents for variable handling

spacecwoboy nginx-forum at
Thu Aug 29 14:42:37 UTC 2013

Is there a way to check a variable against file contents for processing?  A
couple scenarios below.

This is used here, but adding multiple agents can get burdensome:
if ($http_user_agent ~ (agent1|agent2|Foo|Wget|Nmap|BadAgent) ) {
    return 403;
I'd like to maintain a file with all the variables, (and custom script the
addition/removal of file entries) like this:
if ($http_user_agent ~ (in.file(../../badAgents.txt) ) {
    return 403;

Or using file references for Allow/Deny:
Allow ../../whitelist.txt
Deny ../../badHosts.txt

Or Checking usernames against a whitelist/blacklist:
if ( $arg.Username )
if ( $arg.Username )

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

More information about the nginx mailing list