nginx反向代理ajax,解决跨域问题

server {
        listen       8000;
        server_name  somename  alias  another.alias;
        location /a {
            add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
            add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
            add_header 'Access-Control-Expose-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';	
	    add_header 'Access-Control-Allow-Credentials' 'true'; 
            proxy_redirect          off;
            
            proxy_pass https://www.oschina.net/news/widgets/_news_index_all_list?p=2&type=ajax; 
        }
}

  

server {        listen       8000;        server_name  somename  alias  another.alias;            location /a {    add_header 'Access-Control-Allow-Origin' '*';            add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';            add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';            add_header 'Access-Control-Expose-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';add_header 'Access-Control-Allow-Credentials' 'true';             proxy_redirect          off;                        proxy_pass https://www.oschina.net/news/widgets/_news_index_all_list?p=2&type=ajax;         }    }

posted @ 2019-02-24 17:33  httpslly  阅读(759)  评论(0编辑  收藏  举报