设置内容分发网络(CDN)

使用KeyCDN部署

A CDN or content distribution network, is a geographically distributed network of servers that provides high speed internet content. The CDN provides quick, high-quality content delivery for content-heavy websites.

本文档将指导您在Odoo驱动的网站上设置KeyCDN_帐户。

在KeyCDN仪表板中创建一个拉取区域

On the KeyCDN dashboard, start by navigating to the Zones menu item on the left. On the form, give a value to the Zone Name, which will appear as part of the CDN’s URL. Then, set the Zone Status to active to engage the zone. For the Zone Type set the value to Pull, and then, finally, under the Pull Settings, enter the Origin URL— this address should be the full Odoo database URL.

Example

Use https://yourdatabase.odoo.com and replace the yourdatabase subdomain prefix with the actual name of the database. A custom URL can be used, as well, in place of the Odoo subdomain that was provided to the database.

KeyCDN的区域配置页面。

在区域表单下的 常规设置 标题下,点击 显示所有设置 按钮以展开区域选项。这应该是页面上的最后一个选项。展开 常规设置 后,请确保 CORS 选项已经 启用

接下来,滚动到区域配置页面的底部,然后点击 保存 更改。KeyCDN 将指示新区域将被部署。这可能需要大约 10 分钟的时间。

KeyCDN正在部署新区域。

注解

为您的区域生成了一个新的 区域 URL,在本例中为 pulltest-xxxxx.kxcdn.com。这个值对于每个数据库都会有所不同。

将此 Zone URL 复制到文本编辑器中以备后用,因为它将在下一步中使用。

使用新区域配置Odoo实例

In the Odoo Website app, go to the Settings and then activate the Content Delivery Network (CDN) setting and copy/paste the Zone URL value from the earlier step into the CDN Base URL field. This field is only visible and configurable when the developer mode is activated.

注解

Ensure that there are two forward slashes (//) before the CDN Base URL and one forward slash (/) after the CDN Base URL.

完成后,:guilabel:`保存`设置。

在Odoo中激活CDN设置。

Now the website is using the CDN for the resources matching the CDN filters regular expressions.

In the HTML of the Odoo website, the CDN integration is evidenced as working properly by checking the URL of images. The CDN Base URL value can be seen by using your web browser’s Inspect feature on the Odoo website. Look for it’s record by searching within the Network tab inside of devtools.

CDN基础URL可以通过在Odoo网站上使用检查功能来查看。

通过激活跨源资源共享(CORS)来防止安全问题

某些浏览器(如Mozilla Firefox和Google Chrome)中的安全限制会阻止远程链接的CSS文件在同一外部服务器上获取相对资源。

如果在 CDN Zone 中未启用 CORS 选项,则在标准 Odoo 网站上会出现更明显的问题,即缺少 Font Awesome 图标,因为在 Font Awesome CSS 中声明的字体文件将无法从远程服务器加载。

当出现这些跨域资源问题时,类似于以下输出的安全错误消息将出现在Web浏览器的开发人员控制台中:

Font from origin 'http://pulltest-xxxxx.kxcdn.com' has been blocked from loading /shop:1 by Cross-Origin Resource Sharing policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://yourdatabase.odoo.com' is therefore not allowed access.

浏览器控制台中出现了错误消息。

Enabling the CORS option in the CDN settings fixes this issue.