用nginx做反向代理的時候,后臺總是收不到session,發現cookie的屬性有一個Secure,查閱資料說這個屬性會使客戶端在發送請求的時候,如果是http,不會帶上cookie。但我不知道怎么取消這個屬性。
uj5u.com熱心網友回復:
遇到同樣的問題,去查了官網手冊,在1.19.3以后的版本,可以用proxy_cookie_flag實作。
proxy_cookie_flags ~ nosecure;
這個表示去掉所有cookie里的secure屬性,親測可用。
Syntax: proxy_cookie_flags off | cookie [flag ...];
Default:
proxy_cookie_flags off;
Context: http, server, location
This directive appeared in version 1.19.3.
Sets one or more flags for the cookie. The cookie can contain text, variables, and their combinations. The secure, httponly, samesite=strict, samesite=lax, samesite=none parameters add the corresponding flags. The nosecure, nohttponly, nosamesite parameters remove the corresponding flags.
The cookie can also be specified using regular expressions. In this case, cookie should start from the “~” symbol.
Several proxy_cookie_flags directives can be specified on the same configuration level:
proxy_cookie_flags one httponly;
proxy_cookie_flags ~ nosecure samesite=strict;
If several directives can be applied to the cookie, the first matching directive will be chosen. In the example, the httponly flag is added to the cookie one, for all other cookies the samesite=strict flag is added and the secure flag is deleted.
The off parameter cancels the effect of the proxy_cookie_flags directives inherited from the previous configuration level.
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/248692.html
標籤:其他技術討論專區
下一篇:羅斯蒙特流量計應用領域
