nginx跨域設置


nginx跨域問題

例子:訪問http://10.0.0.10/ 需要能實現跨域

操作: http ://10.0.0.10/項目是部署在tomcat里面,tomcat跨域暫時還不會,按照網上的方法操作也沒成功

只有用Nginx做個代理,解決跨域問題了!

 

1、將www.tangxiaoyue.com域名指向http://10.0.0.11/。只有在域名上設置才能實現跨域。(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";
}
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM