2017-09-28 36 views
3

最近我开始使用yandex的分析工具,它为您提供了关于访问者的详细信息,甚至还记录了每个访问者访问您网站的视频。 。该工具的链接是:metrica.yandex.com这是完全免费在nginx中为yandex删除“X-Frame-Options”标题

反正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

改变了我的域名,但它仍然显示我的错误,我不知道为什么,但也许我错过了一些步骤......请你们建议我可能解决方案我需要很多这个选项才能知道我的广告位置

+1

完成后nginx的配置-T' –

回答

1

我最近遇到了与Yandex Metrica相同的问题。他们的错误信息有点误导,因为在我的情况下,原因是Content-Security-Policy设置,而不是X-Frame-Options。检查文档Installing a counter on a site with CSP并尝试添加类似下面的nginx的配置:从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'";