【问题标题】:Removing “X-Frame-Options” header in nginx for a yandex在 nginx 中为 yandex 删除“X-Frame-Options”标头
【发布时间】:2018-03-10 12:15:18
【问题描述】:

最近我开始使用 yandex 的分析工具,它可以为您提供有关访问者的详细信息,即使它会记录每个访问者访问您网站的视频...该工具的链接是:metrica.yandex.com完全免费

无论如何,yandex 工具提供了一个名为地图的选项,它显示了访问者在您的网站上点击最多的地方,所以当我尝试使用它时

我收到一条错误消息说:

 Not possible to replay visit on the given page. Possible reasons:
 Counter code not configured
 Displaying this page in a frame is forbidden

而且我很确定它的计数器代码配置良好,并且我已将其放在我网站上的正确位置,因此我访问了帮助页面链接:yandex.com/support/metrica/behavior/click-map。 html

看看有什么问题所以我发现了

If your site is protected from being shown in an iframe (the X-Frame-Options header is used in the server settings), the collected data won't be available for viewing. To view the site's session data, you must change the server settings and add an exception for the webvisor.com domain and subdomains, as well as for your site's domain. Use the regular expression

他们为使用 nginx 的用户提供了一个代码,需要将其添加到配置文件中以使地图正常工作

所以我添加了它,这是我添加几行后的配置文件

.....    
server_name _;
            location / {
                    # First attempt to serve request as file, then
                    # as directory, then fall back to displaying a 404.
                    try_files $uri $uri/ =404;
                    set $frame_options '';
                    if ($http_referer !~ '^https?:\/\/([^\/]+\.)?(www.google\.com|webvisor\.com)\/'){
                    set $frame_options 'SAMEORIGIN';
            }
                    add_header X-Frame-Options $frame_options;
    }
.....

我已将我的域名更改为 www.google.com

但它仍然向我显示错误我不知道为什么但也许我错过了一些步骤......请大家建议我一个可能的解决方案我非常需要这个选项来知道我可以在哪里放置我的广告

【问题讨论】:

  • nginx -T的输出发布完整的nginx配置

标签: nginx x-frame-options yandex yandex-metrika


【解决方案1】:

我最近在使用 Yandex Metrica 时遇到了同样的问题。他们的错误信息有点误导,因为在我的情况下,原因是Content-Security-Policy 设置,而不是X-Frame-Options。检查Installing a counter on a site with CSP 的文档并尝试在 nginx 配置中添加如下内容:

add_header      Content-Security-Policy "frame-src blob: https://mc.yandex.ru https://mc.yandex.com https://mc.webvisor.com https://mc.webvisor.org";
add_header      Content-Security-Policy "child-src blob: https://mc.yandex.ru https://mc.yandex.com https://mc.webvisor.com https://mc.webvisor.org";
add_header      Content-Security-Policy "script-src 'unsafe-inline' https://yastatic.net https://mc.yandex.ru https://mc.yandex.com 'self'";

【讨论】:

    【解决方案2】:

    在链接https://yandex.com/support/metrica/behavior/click-map.html 他们告诉奇怪的方式,而不是内容安全策略。但正如我所见,我认为域名是webvisor.com。所以你可以将你的内容安全策略定义为*.webvisor.com

    【讨论】:

      猜你喜欢
      • 2015-09-19
      • 1970-01-01
      • 2022-12-18
      • 2017-06-13
      • 2013-11-16
      • 2016-05-29
      • 2020-07-21
      • 2021-12-10
      • 1970-01-01
      相关资源
      最近更新 更多