Nginx 允许多个域名跨域访问
admin • 03/15/2016
当浏览器发起ajax请求到其他域名时,会出现跨域的问题,在nginx上的解决方案是配置Access-Control-Allow-Origin来解决,此参数只允许配置单个域名或者*,当我们需要允许多个域名跨域访问时却不好配置,可以用map来实现
map $http_origin $corsHost { default 0; "~http://www.123admin.com" http://www.123admin.com; "~http://m.123admin.com" http://m.123admin.com; "~http://wap.123admin.com" http://wap.123admin.com; } server { listen 80; server_name search.123admin.com; root /nginx; location / { add_header Access-Control-Allow-Origin $corsHost; } }