我是NGINX
新手,需要指导。
是否可以在Response
饼干上添加secure
和httponly
flags
?
下面是我添加到nginx配置文件的代码:
proxy_cookie_path / "/iwc; secure; HttpOnly";
但是,chrome
上目标响应 Cookie 的HTTP
和secure
列仍未选中。
提前感谢!
我相信你已经从后端设置了cookie。( add-header Set-Cookie
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie(
更好的方法是使用 Nginx 版本 1.19.3 中的proxy_cookie_flags
对于所有饼干,请使用:
proxy_cookie_flags ~ secure samesite=strict;
对于您可以使用的某些 Cookie(或正则表达式(:
proxy_cookie_flags one httponly;
在文档中查看更多信息:https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cookie_flags
请浏览此链接https://geekflare.com/httponly-secure-cookie-nginx/
需要将此模块添加到您的 nginx 并重建 nginx。如何将第三方模块添加到nginx,请点击以下链接https://www.nginx.com/blog/compiling-dynamic-modules-nginx-plus/
并在上面添加proxy_cookie_path set_cookie_flag HttpOnly Secure;在你的nginx.conf文件中,它就可以工作了。
文章 https://geekflare.com/httponly-secure-cookie-nginx/中的proxy_cookie_path设置具有误导性。 它对我不起作用。
实际上,我只是修改nginx.conf如下:
add_header 设置cookie "user=$remote_user;路径=/;仅httpOnly;安全">
然后,它起作用了。