nginx 跨域配置:
if ( $http_origin ~ http://(.*).baidu.com){ set $allow_url $http_origin; } #CORS(Cross Orign Resource-Sharing)跨域控制配置 #是否允许请求带有验证信息 add_header Access-Control-Allow-Credentials true; #允许跨域访问的域名,可以是一个域的列表,也可以是通配符* add_header Access-Control-Allow-Origin $allow_url; #允许脚本访问的返回头 add_header Access-Control-Allow-Headers 'x-requested-with,content-type,Cache-Control,Pragma,Date,x-timestamp'; #允许使用的请求方法,以逗号隔开 add_header Access-Control-Allow-Methods 'POST,GET,OPTIONS,PUT,DELETE'; #允许自定义的头部,以逗号隔开,大小写不敏感 add_header Access-Control-Expose-Headers 'WWW-Authenticate,Server-Authorization'; #P3P支持跨域cookie操作 add_header P3P 'policyref="/w3c/p3p.xml", CP="NOI DSP PSAa OUR BUS IND ONL UNI COM NAV INT LOC"';
server { listen 80; server_name member.baidu.com; root /baidu/data/member ; index index.php index.html index.htm; if (-f $request_filename/index.php){ rewrite (.*) $1/index.php; } if (!-f $request_filename){ rewrite (.*) /index.php; } location ~ \.php { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /baidu/data/member$fastcgi_script_name; include fastcgi_params; if ( $http_origin ~ http://(.*).[(baidu)|(bd)].com ){ set $allow_url $http_origin; } #CORS(Cross Orign Resource-Sharing)跨域控制配置 #是否允许请求带有验证信息 add_header Access-Control-Allow-Credentials true; #允许跨域访问的域名,可以是一个域的列表,也可以是通配符* add_header Access-Control-Allow-Origin $allow_url; #允许脚本访问的返回头 add_header Access-Control-Allow-Headers 'x-requested-with,content-type,Cache-Control,Pragma,Date,x-timestamp'; #允许使用的请求方法,以逗号隔开 add_header Access-Control-Allow-Methods 'POST,GET,OPTIONS,PUT,DELETE'; #允许自定义的头部,以逗号隔开,大小写不敏感 add_header Access-Control-Expose-Headers 'WWW-Authenticate,Server-Authorization'; #P3P支持跨域cookie操作 add_header P3P 'policyref="/w3c/p3p.xml", CP="NOI DSP PSAa OUR BUS IND ONL UNI COM NAV INT LOC"'; } error_log /baidu/logs/nginx/error.member.baidu.log; access_log /baidu/logs/nginx/access.member.baidu.log; }