1aqq
配置有些问题,配置的不对
Kevin6_Wong
服务器支持了,前端走代理就好了,
qq_南方
不报错:
Access-Control-Allow-Origin:*, https://demo.hisouth.cn
报错:
Access-Control-Allow-Origin:*, https://demo.hisouth.cn, https://demo.hisouth.cn
我目前处理:
# 在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;
}
刘樹海
nginx也要配置好
Sellenite
nginx里面,$COOKIE_服务器cookie的名字 ,把“服务器cookie”换成你的cookie就可以取到。
java服务器端添加:
Cookie cookie = new Cookie("testKey", "testVal");
cookie.setDomain(request.getRemoteAddr());
cookie.setPath("/");
cookie.setMaxAge(2 * 60 * 60);
cookie.setHttpOnly(true);
// 写在doFilter前
response.addCookie(cookie);
许小野
求解!
慕工程255496
b.com:8888/test/get1
b.com:8888/test/get1
b.com后面加配置的监听端口号
Cassie_MC
这跟nginx有关,即只有response code为以下value时,才add the specified field:
Adds the specified field to a response header provided that the response code equals 200, 201, 204, 206, 301, 302, 303, 304, or 307. A value can contain variables.
也就是说你本身的接口返回了404,导致add_header没有生效,你可以通过这样设置来让nginx始终添加:
add_header Access-Control-Allow-Origin $http_origin always;
慕斯7911480
设置不同的端口就可以了,老师nginx端口设的是80
Serena_Cecilia
回到上级目录执行一下命令看看
慕粉3770036
nginx -s reload // 重启服务器后再试试