需求:本地访问外域的资源遇到跨域问题。

nginx配置:

server{
        listen       8000;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            #本地项目地址
            root   C:\\Users\\xq\\Desktop\\test\\html;
            #访问资源的页面
            index  index.html index.htm;
        }
        location /portal {
            #远程服务器地址
            proxy_pass       http://aaa.source.com;        
            proxy_set_header Host $host:$server_port;
        }
    }

使用ajax访问:

var proxyUrl =  "portal/api/home/warelist";
        $.ajax({
            url:proxyUrl,
            type:"post",
            contentType:"application/json",
            data:{
                "kindCode":"photograph-TP",
                "providerId":123456
            },
            success:function(result){
                console.log(result);
            }
        });


阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6
标签: nginx