請問下這個問題要怎么處理下
Access to XMLHttpRequest at 'https://api.aaa.com/down_zip/20240525121035561765516.zip' from origin 'https://www.pppp.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
反向代理配置
#PROXY-START/
location ^~ /
{
proxy_pass http://127.0.0.1:1300;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_http_version 1.1;
# proxy_hide_header Upgrade;
add_header Access-Control-Allow-Origin "*";
add_header Access-Control-Allow-Methods "*";
add_header Access-Control-Allow-Headers "authorization, token";
add_header X-Cache $upstream_cache_status;
#Set Nginx Cache
set $static_filevO5uJYW3 0;
if ( $uri ~* "\.(gif|png|jpg|css|js|woff|woff2)$" )
{
set $static_filevO5uJYW3 1;
expires 1m;
}
if ( $static_filevO5uJYW3 = 0 )
{
add_header Cache-Control no-cache;
}
}
#PROXY-END/
靜態(tài)資源一般都走的nginx,是否跨域與webman已經(jīng)沒有關(guān)系了,需要nginx里配置跨域頭,并重啟nginx。
如果還是提示 No 'Access-Control-Allow-Origin' header is present 那就是nginx哪里沒設(shè)置對或沖突了
NGINX:
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' '*';
add_header 'Access-Control-Allow-Headers' '*';
app\middleware\AccessControl::process:
// 如果是options請求則返回一個空響應(yīng),否則繼續(xù)向洋蔥芯穿越,并得到一個響應(yīng)
$response = $request->method() == 'OPTIONS' ? response('') : $handler($request);
// 給響應(yīng)添加跨域相關(guān)的http頭
// $response->withHeaders([
// 'Access-Control-Allow-Credentials' => 'true',
// 'Access-Control-Allow-Origin' => $request->header('origin', '*'),
// 'Access-Control-Allow-Methods' => $request->header('access-control-request-method', '*'),
// 'Access-Control-Allow-Headers' => $request->header('access-control-request-headers', '*'),
// ]);
return $response;