nginx跨域问题
例子:访问http://10.0.0.10/ 需要能实现跨域
操作:
只有用Nginx做个代理,解决跨域问题了!
1、将www.tangxiaoyue.com域名指向。只有在域名上设置才能实现跨域。(10.0.0.11是Nginx的IP)
2、在nginx上的配置文件tang.conf进行设置
配置文件例如:
server {listen 80;server_name tangxiaoyue.com;if ( $http_user_agent = "Mozilla/5.0"){return 403;}location / {add_header 'Access-Control-Allow-Origin' '*';## Om nom nom cookies#add_header 'Access-Control-Allow-Credentials' 'true';add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';# # Custom headers and headers various browsers *should* be OK with but aren't#add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';proxy_pass http://10.0.0.10/;proxy_set_header Host "tangxiaoyue";}}