javascript - nginx反向代理解决跨域的疑问
PHP中文网
PHP中文网 2017-04-11 12:26:51
0
2
281

localhost:80下的页面通过ajax,去调取localhost:8082/api/v1.0/testapi的数据,如下nginx配置问题在哪儿?谢谢

server {

    listen       80;
    server_name  localhost;

    location /api/v1.0 {
        proxy_pass http://localhost:8082/api/v1.0;
    }
    location / {
        root   html;
        index  index.html index.htm;
    }

}

ajax调用:

$.ajax({

url:'/api/v1.0/testapi',
success: function(data){
    console.log(data)
}

});

PHP中文网
PHP中文网

认证高级PHP讲师

répondre à tous(2)
阿神

server块中 server_name下面追加头信息

server {
    .....
    add_header Access-Control-Allow-Origin *;
    add_header Access-Control-Allow-Credentials true;
    ....
}

另外* 可以替换成具体的请求URL地址

PHPzhong

似乎木有看到错误

Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!