需要多个字符串

问题描述 投票:0回答:1

我想摆脱所有攻击我网站的机器人。

这是我的会议:

<RequireAll>
    Require all granted
    Require expr %{HTTP_USER_AGENT} != 'Go-http-client/1.1'
    Require expr %{HTTP_USER_AGENT} != 'Go-http-client/2.0'
    Require expr %{HTTP_USER_AGENT} != 'Custom-AsyncHttpClient'
    Require expr %{HTTP_USER_AGENT} != 'python-requests/2.21.0'
    Require expr %{HTTP_USER_AGENT} != 'python-requests/2.22.0'
    Require expr %{HTTP_USER_AGENT} != 'python-requests/2.23.0'
    Require expr %{HTTP_USER_AGENT} != 'l9explore/1.2.2'
</RequireAll>

问题是,从我的日志中,我看到有 15 个不同的 python 请求版本号。

  • “python-requests/2.21.0”
  • “python-requests/2.22.0”
  • “python-requests/2.23.0”
  • “python-requests/2.24.0”
  • “python-requests/2.25.1”
  • “python-requests/2.26.0”
  • “python-requests/2.27.1”
  • “python-requests/2.28.1”
  • “python-requests/2.28.2”
  • “python-requests/2.31.0”
  • “python-requests/2.32.0”
  • “python-requests/2.32.1”
  • “python-requests/2.32.2”
  • “python-requests/2.32.3”
  • “python-requests/2.6.0”

有没有办法说“所有 python 请求”?我已经尝试过以下方法,但 apachectl configtest 抱怨:

需要 expr %{HTTP_USER_AGENT} !~ 'python-requests'

谢谢你

apache apache-config
1个回答
0
投票

expr
后面可以跟任何有效表达式。您可以使用正则表达式...

Require expr %{HTTP_USER_AGENT} =~ m#python-requests/#

或带有通配符的

strmatch

Require expr %{HTTP_USER_AGENT} -strmatch 'python-requests/*'
© www.soinside.com 2019 - 2024. All rights reserved.