溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Nginx出現(xiàn)雙跨域問題解決

發(fā)布時(shí)間:2020-08-07 16:24:03 來源:網(wǎng)絡(luò) 閱讀:447 作者:hanye韓也 欄目:系統(tǒng)運(yùn)維
Nginx作為代理,出現(xiàn):The 'Access-Control-Allow-Origin' header contains multiple values ', ', but only one is allowed 錯(cuò)誤。

Nginx出現(xiàn)雙跨域問題解決

服務(wù)器端允許跨域

location / {
add_header 'Access-Control-Allow-Origin' $http_origin;
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,web-token,app-token,Authorization,Accept,Origin,Keep-Alive,User-Agent,X-Mx-ReqToken,X-Data-Type,X-Auth-Token,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain; charset=utf-8';
add_header 'Content-Length' 0;
return 204;
}

報(bào)錯(cuò)處理

看上面錯(cuò)誤提示,contains multiple values "*" 意思就是設(shè)置了2次跨域,我們這邊是我在nginx里面設(shè)置了跨域,開發(fā)在程序里面也設(shè)置了跨域處理,但是只有一個(gè)是允許的,移除其中的任意一個(gè)就好了。如果服務(wù)器設(shè)置了允許跨域,使用Nginx代理里面就不需要設(shè)置跨域了。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI