删除nginx中的“X-Frame-Options”标头以获取yandex

时间:2017-09-28 16:51:25

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

最近我开始使用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

更改了我的域名

但它仍然向我展示的错误我不知道为什么但也许我错过了一些步骤...请各位建议我一个可能的解决方案我需要这个选项很多才能知道我可以把我的广告放在哪里

2 个答案:

答案 0 :(得分: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'";

答案 1 :(得分:0)

在链接https://yandex.com/support/metrica/behavior/click-map.html上,他们讲的是奇怪的方法,而不是内容安全策略。但据我所知,该域仅是我认为的webvisor.com。因此,您可以将内容安全策略定义为*.webvisor.com