Welcome! Log In Create A New Profile

Advanced

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

Maxim Dounin
August 29, 2013 01:44PM
Hello!

On Thu, Aug 29, 2013 at 10:42:37AM -0400, spacecwoboy wrote:

> 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 does.not.exist.in(../../allowedUsers.txt) )
> if ( $arg.Username exists.in(../../blockedUsers.txt) )

The map module is probably what you are looking for, see here:

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

Additionally, the "include" directive may be usefull, see
http://nginx.org/r/include.

--
Maxim Dounin
http://nginx.org/en/donation.html

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

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

spacecwoboy August 29, 2013 10:42AM

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

Maxim Dounin August 29, 2013 01:44PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 274
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready