修改配置文件可通过如下配制进行多域名的设置。 map $http_origin $corsHost { default 0; "~https://www.itbiancheng.com" https://www.itbiancheng.com; "~http://love.itbiancheng.com" http://love.itbiancheng.com;}server{ listen 80; server_name www.itbiancheng.com; root /nginx; location / { add_header Access-Control-Allow-Origin $corsHost; }} 最近在做一个站,由于把样式和图片都独立出来了一个单独的域名,在移动端的时候访问提示跨域访问了,主要是因为css样式里面引用了字体文件,接下来吾爱编程为大家介绍一下,有需要的小伙伴可以参考一下:
1、错误提示
2、解决方法nginx上的解决方案是配置Access-Control-Allow-Origin来解决,但是要么允许所有,要么允许单个的,都不能解决我的文件,经过一番查找找到了解决方法, map $http_origin $corsHost { default 0; "~https://www.itbiancheng.com" https://www.itbiancheng.com; "~http://love.itbiancheng.com" http://love.itbiancheng.com;}server{ listen 80; server_name www.itbiancheng.com; root /nginx; location / { add_header Access-Control-Allow-Origin $corsHost; }} 下载地址: Windows 使用docker快速部署Nginx、Redis、MySQL、Tomcat及制作镜像的方法 |