nginx - 为 yandex 删除 nginx 中的 “X-Frame-Options” header

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

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

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

我收到一条错误消息说:

 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 的用户一个代码,需要将它添加到配置文件中才能使 map 正常工作

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

.....    
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

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

最佳答案

我最近在使用 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'";

关于nginx - 为 yandex 删除 nginx 中的 “X-Frame-Options” header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46474453/

相关文章:

testing - Yandex-tank - 多个具有不同 http header 的请求

android - Yandex Marker 在 Android 中的当前 Latlong 值

java - Yandex API 地理编码

nginx - HAproxy 端口 80 和 443 到后端 :80 and backend:443

mysql - MariaDB/MySQL 突然崩溃并且无法重新启动

python - Virtualenv:如何使自定义 Python 包含由 uWSGI 托管的多组件共享

python - 在 docker 容器中使用 uwsgi 和 nginx 设置 Flask 应用程序

javascript - Google Drive API,无法通过 JS 打开标准共享对话框(x-frame-options 错误)

ruby-on-rails - 将 X-Frame-Options 添加到 Heroku Rails 2.3.15 应用程序

security - x-frame-options 的重复值