当使用Apache2作为Web服务器,并通过Cloudflare进行反向代理时,可能会遇到"URL对Google不可用"或"获取失败:爬取异常"的错误。这通常是由于Cloudflare的安全策略导致的。
以下是解决此问题的一些可能方法,包含代码示例:
debug
,以便更详细地查看错误日志。可以通过编辑Apache2的配置文件/etc/apache2/apache2.conf
,将以下行添加到文件中:LogLevel debug
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
部分以允许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
这些方法应该有助于解决"URL对Google不可用"或"获取失败:爬取异常"的错误。请根据您的具体环境和需求进行调整和测试。