说明
在https环境中,等保要求为 set-cookie增加secure属性(为了安全,防止http请求时使用此cookie)
解决办法
server {
listen 80;
listen [::]:80;
client_max_body_size 200m;
root /usr/local/www/;
access_log /dev/null;
error_log /dev/stderr;
proxy_cookie_path / "/; httponly;secure; SameSite=Lax";
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection 1;
add_header X-Frame-Options SAMEORIGIN;
location / {
index index.html index.htm;
try_files $uri /index.html;
}
}
如上配置,在全局server中添加:proxy_cookie_path / "/; httponly;secure; SameSite=Lax";配置
验证方法
打开浏览器的开发者工具(通常是按下F12键),切换到“Network”或“网络”选项卡。
访问您配置了添加Secure标记的网站。
在开发者工具中,选择与您访问的网站对应的请求(通常是网站首页的请求)。
检查“Response Headers”(或类似名称),查找名为“Set-Cookie”的响应头。
如果在Cookie中包含了
secure
属性,就表示Nginx已成功为Cookie添加了Secure标记。