S
S
Sergey Vasiliev2021-09-03 23:44:42
PHP
Sergey Vasiliev, 2021-09-03 23:44:42

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

4 answer(s)
S
shurshur, 2021-09-04
@Romo4ka_eto_ia

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

I
Ivan Kulakov, 2021-09-04
@ivankprod

See here:
https://qna.habr.com/q/488123

S
SKEPTIC, 2021-09-04
@pro100chel

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.

V
Vasili78, 2021-09-06
@Vasili78

At the fpm level, you can set
phpvalue[session.cookiedomain] = ".domain.ru"
The session will be transferred.
Or at the time of authorization, you can run through all subdomains by setting a cookie and return to the desired subdomain.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question