要将nginx设置Cookie的“secure”属性设置为“true”,需要在nginx配置文件中添加以下行:

server {
  listen 80;
  server_name example.com;

  location / {
    proxy_pass http://backend;
    proxy_cookie_path / "/; secure";
  }
}

在以上示例中,“/; secure”将设置所有Cookie的“secure”属性为“true”。这将确保Cookie仅在HTTPS连接上发送,并且无法通过非加密连接(例如HTTP)访问Cookie。

请注意,如果您的网站不支持HTTPS,则不应将所有Cookie设置为“secure”属性为“true”。在这种情况下,您应该只将敏感Cookie(如身份验证Cookie)设置为“secure”属性为“true”。

nginx设置Cookie的secure属性设置为true

原文地址: https://www.cveoy.top/t/topic/feAp 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录