在一个简单的网站上违反了内容安全策略指令

Content Security Policy directive violated on a simple website

很抱歉打扰你,但我正在开发我的个人网站并尝试整合 Google 地图(感谢 codepen 提供的出色模板)。

但我不得不面对反复出现的 CSP 错误消息,导致地图无法加载:

Refused to load the script 'https://maps.googleapis.com/maps/api/js?key=AIzaSyBlSsS5JzdJLsuMEY24xeLAZOc7JAH6sr8' because it violates the following Content Security Policy directive: "script-src 'self' www.google-analytics.com".

我在问我的问题之前进行了研究,因为这对很多人来说似乎是个问题。我尝试了一切,包括删除 Google Analytics 脚本并添加:

<meta http-equiv="Content-Security-Policy" content="script-src 'self' https://apis.google.com https://maps.googleapis.com https://maps.gstatic.com www.google-analytics.com ajax.googleapis.com; object-src 'self'">

但这并没有改变任何东西。我的地图无法加载,这让我很生气!

你知道我做错了什么吗?非常感谢你的帮助 ! (如果需要,我可以实时向您展示错误,但我不想 "promote" 我的网站在这里)

您的 .htaccess 文件的第 479 行说:

Header set Content-Security-Policy "script-src 'self' www.google-analytics.com"

不确定您的 meta 标签是否可以覆盖它。

您可能应该修改 .htaccess 文件中的那一行,以包含您的其他来源(对于 Google 地图,“https://maps.googleapis.com”)。