Laravel-cors 跨域

 

解决跨域问题 barryvdh/Laravel-cors: https://learnku.com/articles/42923

 composer

"league/flysystem": "1.1",

 app.php

//filesystems
$app->configure('filesystems');

  

$app->middleware([
    Barryvdh\Cors\HandleCors::class,
]);

 

其他原因

The 'Access-Control-Allow-Origin' header contains multiple values'*, *', but only one is allowed.

https://www.cnblogs.com/zsg88/articles/11576324.html

 

还有可能是nginx转发导致nginx.conf多次add_haerder引起的报错

http {

    add_header Access-Control-Allow-Origin *;
    add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
    add_header Access-Control-Allow-Headers 
    ...
}

  

可以在nginx转发规则前后使用proxy_hide_header隐藏之前声明的头参数

location ^~ /v2/ {
        proxy_pass http://127.0.0.1:8091;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        proxy_hide_header Access-Control-Allow-Origin;
        proxy_hide_header Access-Control-Allow-Methods;
        proxy_hide_header Access-Control-Allow-Headers;

    }

  

 

posted @ 2020-10-24 11:45  程序生(Codey)  阅读(372)  评论(0编辑  收藏  举报