The 'Access-Control-Allow-Origin' header contains multiple values 'http://localhost:8082, http://localhost:8082', but only one is allowed.
The 'Access-Control-Allow-Origin' header contains multiple values 'http://localhost:8082, http://localhost:8082', but only one is allowed.
可否在NGINX里,預(yù)先判斷是否包含與$http_origin相同信息,如果有,則不添加。
使用服務(wù)器測(cè)試頁(yè),訪問(wèn)正常。http://test.hisouth.cn/websocket02/?,請(qǐng)求頭信息正常。
使用本地測(cè)試頁(yè),http://localhost:8082/,連接服務(wù)器WebSocket,就會(huì)出現(xiàn)多請(qǐng)求origin。
我找不到,在哪添加了兩次(這里面使用的sockjs)。
請(qǐng)問(wèn),如果NGINX配置了跨域,而前端又添加,允許跨域請(qǐng)求頭,是否會(huì)出現(xiàn)這樣的重復(fù)問(wèn)題。
http&http跨域
另外,請(qǐng)問(wèn)websocket連接中,是否不允許重定向操作。
2020-03-27
不報(bào)錯(cuò):
報(bào)錯(cuò):
我目前處理:
# 在options中,添加一次跨域請(qǐng)求
# https://www.cnblogs.com/sunmmi/articles/5956554.html
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' $http_origin;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
add_header 'Access-Control-Max-Age' 86400;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
# 最后判斷再匹配一次
# nginx 正則表達(dá)式
# https://www.cnblogs.com/bethal/p/5514557.html
if ($http_origin !~* '^http'){
add_header 'Access-Control-Allow-Origin' $http_origin;
}