Dr.*_*ibo 11 rewrite nginx reverse-proxy cookies
使用 Nginx 作为反向代理,如何在 cookie 中添加 samesite=strict 或 samesite=lax?
小智 16
使用此代码,您可以使用proxy_cookie_path
(http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cookie_path)将所有应用程序 cookie 定义为安全、httponly 和/或相同站点
location / {
# your usual config ...
# hack, set all cookies to secure, httponly and samesite (strict or lax)
proxy_cookie_path / "/; secure; HttpOnly; SameSite=strict";
}
Run Code Online (Sandbox Code Playgroud)
我在不支持samesite
属性的网络应用程序中遇到了类似的问题。我已经创建了与@Beccari 解决方案类似的解决方法:
proxy_cookie_path ~^/(.+)$ "/$1; SameSite=none";
Run Code Online (Sandbox Code Playgroud)
你必须把它放在适当的上下文中,就我而言,在location
. 如果您需要none
像我这样设置值,请记住您也必须添加Secure
属性才能为其他网站启用第三方 cookie。
小智 6
我认为更好的方法是使用 Nginx 版本 1.19.3 中的 proxy_cookie_flags
对于所有 cookie 使用:
proxy_cookie_flags ~ secure samesite=strict;
Run Code Online (Sandbox Code Playgroud)
对于某些 cookie,您可以使用(或正则表达式):
proxy_cookie_flags one httponly;
Run Code Online (Sandbox Code Playgroud)
查看文档中的更多信息:https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cookie_flags
归档时间: |
|
查看次数: |
36235 次 |
最近记录: |