Answer the question
In order to leave comments, you need to log in
How to transfer cookies through nginx?
Hello, there are 2 sites: sub.domain.ru and domain.ru, both are on the same machine on nginx. It is necessary that when you visit any of the sites, the cookies are the same. For example, the site sub.domain.ru set session cookies. The person went to the site domain.ru and the same cookies were there.
Answer the question
In order to leave comments, you need to log in
This is not really an nginx issue. The browser decides which cookies to consider and send in a request to a particular domain, and it must do this in accordance with RFC 6265 (not to be confused with the outdated RFC 2109, 2965, there are differences).
In short, sub.domain.com can place a cookie on both sub.domain.com and just on domain.com (in this case, it will also affect all subdomains of the same level as sub.domain.com). But domain.com cannot set a cookie on the com domain, because there must be at least one dot in the domain (such protection).
For experiments, you can play around with cookies in this sandbox with subdomains: https://scripts.cmbuckley.co.uk/cookies.php and see
You don't have to do it through nginx.
It is enough to specify the necessary parameters when setting the cookie. (Domain *.domain.ru). In this case, the cookie will be set for the main domain or subdomains.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question