【发布时间】:2018-03-07 10:27:03
【问题描述】:
我遇到了一些跨域图片的问题,希望你能帮忙。
这里的行为。 我有 2 个域,例如: - domain1.com - domain2.com
在 domain1 上我放了很多 html5 游戏。此域只是游戏的存储库。
Domain2 是真正的网站(wordpress 网站),用户可以在其中玩 domain1 上托管的游戏。 为此,我为每场比赛都提出了 curl 请求。
在 domain1 nginx 配置文件中,我将这些代码行用于启用跨域资源共享:
位置~* \.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|json|js|jpg|jpeg|gif|png|ico|zip|tgz|gz| rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf|swf|mp3|xml|woff2)$ { add_header "Access-Control-Allow-Origin" "*"; access_log 关闭; log_not_found 关闭; 最大过期; }这解决了许多游戏的一些问题,但有些游戏仍然无法运行,我收到这个 js 错误:
未捕获的 DOMException:无法在“WebGLRenderingContext”上执行“texImage2D”:可能无法加载 http://domain1.com/html5-games/action/candy-match/images/loadingbarbackground-sheet0.png 处的跨域图像。 在 GLWrap_.loadTexture (http://domain1.com/html5-games/action/candy-match/c2runtime.js:2618:16) 在 pluginProto.Type.typeProto.loadTextures (http://domain1.com/html5-games/action/candy-match/c2runtime.js:18070:46) 在 pluginProto.Instance.instanceProto.onCreate (http://domain1.com/html5-games/action/candy-match/c2runtime.js:18146:13) 在 Runtime.createInstanceFromInit (http://domain1.com/html5-games/action/candy-match/c2runtime.js:4806:8) 在 Layer.createInitialInstances (http://domain1.com/html5-games/action/candy-match/c2runtime.js:7541:25) 在 Layout.startRunning (http://domain1.com/html5-games/action/candy-match/c2runtime.js:6715:10) 在 Runtime.go_loading_finished (http://domain1.com/html5-games/action/candy-match/c2runtime.js:4067:36) 在 Runtime.go (http://domain1.com/html5-games/action/candy-match/c2runtime.js:3966:9) 在 http://domain1.com/html5-games/action/candy-match/c2runtime.js:4025:60我在网上做了一些研究,发现了这样的文章 https://webglfundamentals.org/webgl/lessons/webgl-cors-permission.html Drawing images to canvas with img.crossOrigin = "Anonymous" doesn't work
但它们不是很有帮助。
我不想修改原始游戏文件。如果存在,我正在寻找服务器端解决方案。如果没有,您有解决我的问题的想法吗?
我的配置有错误吗?我错过了什么吗?
感谢您的帮助。
瓦莱里奥
【问题讨论】:
-
您是否通过浏览器开发工具检查过您的 domain1 服务器是否确实返回了正确的标头?
-
嗨@CBroe 显然标头似乎没问题。HTTP/1.1 200 OK 服务器:nginx/1.6.2 日期:星期二,2017 年 9 月 26 日 09:33:11 GMT 内容类型:文本/html 内容-长度:4431 最后修改时间:2017 年 9 月 26 日星期二 08:00:45 GMT 连接:保持活动 ETag:“59ca092d-114f”接受范围:字节
-
我的意思是图片...
-
呃,对不起@CBroe,这是我为图片获取的标题imgur.com/a/huxPq
-
尝试将访问控制标头设置为实际域而不是通配符,也可以尝试其他浏览器以获取更详细的错误消息。
标签: javascript html nginx cors webgl