首页 > 解决方案 > 在 ubuntu 服务器上,nginx 无法提供跨域图像 url

问题描述

我已经使用 Django 框架开发项目并从http://data.myothersite.org/data/images/agents/A_1747.jpg获取图像文件

在本地主机中,我已经测试并能够在我的列表页面中获取所有图像,但是在具有域的实时服务器上,http://www.myfirstsite.org我无法获取托管的所有图像http://data.myothersite.org并获得权限被拒绝错误。

我试图add_header Access-Control-Allow-Origin 在 nginx conf 文件中设置 http://data.myothersite.org/` 但没有任何运气。

我也尝试在网上找到解决方案,但无法找到。

谢谢。

标签: pythondjangonginx

解决方案


由于http://www.myfirstsite.org要从加载图像http://data.myothersite.org,因此必须在 nginx conf 中提供权限,http://data.myothersite.org而不是在 nginx conf 中http://www.myfirstsite.org

在 nginx conf 中提供此标头http://data.myothersite.org

add_header 'Access-Control-Allow-Origin' 'http://www.myfirstsite.org' always;

参考:https ://enable-cors.org/server_nginx.html


推荐阅读