Symptoms
When Nginx caching is enabled with default settings, all pages with a cookie (even _gid
only) are not cached by default, the response header contains: x-cache-status:
BYPASS
Cause
That is the expected behavior.
According to Plesk documentation:
By default, nginx does not cache HTTP requests that contain the Cookie HTTP header. You can change this behavior and have nginx cache HTTP requests containing certain cookies by specifying the names of the cookies in the “Cache requests with cookies” field.
The caching for pages using cookies and/or user-specified parameters should be configured very carefully since it may compromise website security or lead to incorrect behavior of a web application, that is why this feature is disabled by default. The same logic applies to the default Nginx behavior as per Nginx documentation:
It does not cache responses with ... Set-Cookie in the response header. You can override these defaults as described in the answers below.
Resolution
This behavior can be changed to make Nginx cache HTTP requests containing certain cookies by specifying the names of the cookies in the Cache requests with cookies field:
-
Go to Domains > example.com > Apache and Nginx Settings.
-
Specify required cookie names in the Cache requests with cookies field.
For example,
_ga
and_gid
cookie names are specified, Nginx will only cache HTTP requests with cookie headers that contain_ga
or_gid
.