Apache2在Cloudflare反向代理后 - “URL对Google不可用”获取失败:爬取异常
创始人
2024-09-05 07:31:26
0

当使用Apache2作为Web服务器,并通过Cloudflare进行反向代理时,可能会遇到"URL对Google不可用"或"获取失败:爬取异常"的错误。这通常是由于Cloudflare的安全策略导致的。

以下是解决此问题的一些可能方法,包含代码示例:

  1. 确保Apache2的日志级别设置为debug,以便更详细地查看错误日志。可以通过编辑Apache2的配置文件/etc/apache2/apache2.conf,将以下行添加到文件中:
LogLevel debug
  1. 在Apache2的虚拟主机配置中,添加mod_remoteip模块以解析真实的客户端IP地址。这可以通过编辑虚拟主机配置文件(通常是/etc/apache2/sites-available/000-default.conf)来完成,将以下行添加到标签中:
RemoteIPHeader CF-Connecting-IP
RemoteIPTrustedProxy 103.21.244.0/22
RemoteIPTrustedProxy 103.22.200.0/22
RemoteIPTrustedProxy 103.31.4.0/22
RemoteIPTrustedProxy 104.16.0.0/12
RemoteIPTrustedProxy 108.162.192.0/18
RemoteIPTrustedProxy 131.0.72.0/22
RemoteIPTrustedProxy 141.101.64.0/18
RemoteIPTrustedProxy 162.158.0.0/15
RemoteIPTrustedProxy 172.64.0.0/13
RemoteIPTrustedProxy 173.245.48.0/20
RemoteIPTrustedProxy 188.114.96.0/20
RemoteIPTrustedProxy 190.93.240.0/20
RemoteIPTrustedProxy 197.234.240.0/22
RemoteIPTrustedProxy 198.41.128.0/17
RemoteIPTrustedProxy 2400:cb00::/32
RemoteIPTrustedProxy 2606:4700::/32
RemoteIPTrustedProxy 2803:f800::/32
RemoteIPTrustedProxy 2405:b500::/32
RemoteIPTrustedProxy 2405:8100::/32
  1. 在Apache2配置文件中,添加以下部分以允许Cloudflare的IP地址通过Apache2的访问控制列表(ACL):

    Require all granted
    Allow from 103.21.244.0/22
    Allow from 103.22.200.0/22
    Allow from 103.31.4.0/22
    Allow from 104.16.0.0/12
    Allow from 108.162.192.0/18
    Allow from 131.0.72.0/22
    Allow from 141.101.64.0/18
    Allow from 162.158.0.0/15
    Allow from 172.64.0.0/13
    Allow from 173.245.48.0/20
    Allow from 188.114.96.0/20
    Allow from 190.93.240.0/20
    Allow from 197.234.240.0/22
    Allow from 198.41.128.0/17
    Allow from 2400:cb00::/32
    Allow from 2606:4700::/32
    Allow from 2803:f800::/32
    Allow from 2405:b500::/32
    Allow from 2405:8100::/32

  1. 在Cloudflare的设置中,禁用"防火墙"和"爬虫"功能,以便允许Apache2与Google的爬虫进行通信。

这些方法应该有助于解决"URL对Google不可用"或"获取失败:爬取异常"的错误。请根据您的具体环境和需求进行调整和测试。

相关内容

热门资讯

安装apache-beam==... 出现此错误可能是因为用户的Python版本太低,而apache-beam==2.34.0需要更高的P...
避免在粘贴双引号时向VS 20... 在粘贴双引号时向VS 2022添加反斜杠的问题通常是由于编辑器的自动转义功能引起的。为了避免这个问题...
Android Recycle... 要在Android RecyclerView中实现滑动卡片效果,可以按照以下步骤进行操作:首先,在项...
omi系统和安卓系统哪个好,揭... OMI系统和安卓系统哪个好?这个问题就像是在问“苹果和橘子哪个更甜”,每个人都有自己的答案。今天,我...
原生ios和安卓系统,原生对比... 亲爱的读者们,你是否曾好奇过,为什么你的iPhone和安卓手机在操作体验上有着天壤之别?今天,就让我...
Android - 无法确定任... 这个错误通常发生在Android项目中,表示编译Debug版本的Java代码时出现了依赖关系问题。下...
Android - NDK 预... 在Android NDK的构建过程中,LOCAL_SRC_FILES只能包含一个项目。如果需要在ND...
Akka生成Actor问题 在Akka框架中,可以使用ActorSystem对象生成Actor。但是,当我们在Actor类中尝试...
Agora-RTC-React... 出现这个错误原因是因为在 React 组件中使用,import AgoraRTC from “ago...
Alertmanager在pr... 首先,在Prometheus配置文件中,确保Alertmanager URL已正确配置。例如:ale...