背景: 1、nginx 需要设置,以达成通过http的形式访问,重定向到另外一台服务上。但是通过前端排查,浏览器前端set cookie 一直没有通过(被拦截了)。原因是set cookie带有secure属性,无法应用于http。set cookie属性如果为true,则只能应用于https上。 2、已知,已经设置了 http only属性。

处理方式: 通过添加一个map相关的指令以及在location中添加对应的add_head来去除set cookie相关的secure属性


map $sent_http_set_cookie $resp_cookie {
    ~*(?<CK>.+)Secure $CK;
}

server {
  listen 80;
  server_name  locathost;

  location ^~/test{
    proxy_pass http://test;
    add_header Set-Cookie $resp_cookie;
    #其他更多配置...

  #其他更多配置...
}
 

 
}