You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AMP页面无法加载Google Adsense广告:跨域框架访问被阻排查

AMP页面部署在Nginx上无法加载Google Adsense广告,跨域框架访问被阻止

最近把站点DNS迁移到支持HTTPS的新服务器后,我遇到了一个头疼的问题:部署在Nginx上的AMP页面能正常加载,但Google Adsense广告完全显示空白,广告位置一片空。

我已经查过Stack Overflow、Google Adsense官方文档和Amp By Example的相关内容,严格按照官方说明添加了amp-ad组件,而且Adsense后台显示我的站点已经通过验证,但广告就是不出来。

打开浏览器控制台,我看到重复出现两次这个错误:

Blocked a frame with origin "https://d-1234567890.ampproject.net" from accessing a frame with origin "https://example.com". Protocols, domains, and ports must match.

我初步怀疑是跨域相关的问题,目前我的站点和AMP的域名都是HTTPS,协议是匹配的,但不确定域名与端口是否完全匹配,不知道该怎么验证这一点?

除了盲目去关闭服务器的安全措施,我实在不知道该从哪里下手排查了,想请教各位大佬:

  • 是否需要检查Nginx配置里的X-Frame-Options、X-Content-Type-Options或者Content-Security-Policy这些响应头?会不会是这些头限制了框架的访问?
  • Google Adsense会不会还在使用旧的HTTP协议发起请求?毕竟我刚迁移到HTTPS服务器不久。
  • 控制台还弹出了两个预加载资源未使用的警告,会不会和广告加载失败有关?
    [Warning] The resource https://3p.ampproject.net/234567890/f.js was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it wasn't preloaded for nothing.
    [Warning] The resource https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it wasn't preloaded for nothing.
    

内容的提问来源于stack exchange,提问作者Geekomancer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 04:16:17