2017-09-28 34 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'";