location regex?

Jay Haines jeh253 at gmail.com
Thu Aug 4 00:39:32 UTC 2022


I am trying to weed out requests for any uri that contains the string, 
"announce" (no quotes). That would include

  * /announce
  * /announce/
  * /announce.php

each with or without query strings. I have the following location blocks 
in my server context:

        location ~* announce {
                return 444;
        }

        location ~* /announce.php {
                return 444;
        }

and my log looks good:

"122.100.172.162"       "03/Aug/2022:20:19:00 -0400"    "GET 
/announce.php?info_hash=%DF%AEF%40%7F%1DA%C9%91S%9F%D4%0D%D6J%E6%992%A3~&peer_id=-BC0171-_sSI%D1n%AA%A9%C3%A5%25%1E&port=15302&natmapped=1&localip=172.18.80.247&port_type=lan&uploaded=46317568&downloaded=11285925264&left=178446055&numwant=50&compact=1&no_peer_id=1&key=38892 
HTTP/1.1"        "444"   "0"     "0.000"  "-"     "BitComet/1.71.9.7"


until it doesn't:

"81.110.165.170"        "03/Aug/2022:20:24:03 -0400"    "GET 
/announce.php?info_hash=%5B%EA0r%8A*8%C4%DAA%81%02%B4%BF%97%CC%1E%A9y%C8&am_peer_id=-TR300%5A-LDXTt3fAIyq%00&port=43342&uploaded=0&downloaded=0&left=5593535899&event=started&key=0&compact=1&numwant=200 
HTTP/1.1" "400"   "150"   "0.000" "-"     "-"


I have tried various location prefixes and regexes (and combinations 
thereof) but can't seem to find the one that works correctly.

Thanks for any help
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20220803/8aa8b9c7/attachment.htm>


More information about the nginx mailing list