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里,預先判斷是否包含與$http_origin相同信息,如果有,則不添加。
使用服務器測試頁,訪問正常。http://test.hisouth.cn/websocket02/?,請求頭信息正常。
使用本地測試頁,http://localhost:8082/,連接服務器WebSocket,就會出現多請求origin。
我找不到,在哪添加了兩次(這里面使用的sockjs)。
請問,如果NGINX配置了跨域,而前端又添加,允許跨域請求頭,是否會出現這樣的重復問題。
http&http跨域
另外,請問websocket連接中,是否不允許重定向操作。
2020-03-27
不報錯:
報錯:
我目前處理:
# 在options中,添加一次跨域請求
# 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 正則表達式
# https://www.cnblogs.com/bethal/p/5514557.html
if ($http_origin !~* '^http'){
add_header 'Access-Control-Allow-Origin' $http_origin;
}