nginx解决微信头像canvas跨域问题

1.背景介绍

微信h5界面需要生成截图,采取前端canvas的方案,出现跨域

2.解决方案

假设界面是
aa.bb.cc/mydemo/index.html
在nginx里配置

	location /mydemo/wechat/image/{
		add_header 'Access-Control-Allow-Origin' "$http_origin" always;
		add_header 'Access-Control-Allow-Credentials' 'true' always; 
		add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS' always; 
		add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-  Since,Keep-Alive,Origin,User-Agent,X-Requested-With' always;
		proxy_pass http://thirdwx.qlogo.cn/;
	}

这样,在

aa.bb.cc/mydemo/wechat/image/+xxx

的链接上即可访问微信头像图片,不会再导致canvas跨域错误

你可能感兴趣的:(运维工作经验笔记)