Magento Nginx: cache first page request only (no session) for super speed
In an effort (and test) to make Magento fly I was playing with microcaching in Magento and came up with the following.
The idea is to: detect a first visit and return visit. A return visit may already have an item in the cart or some session params so we need the dynamic full (slow) Magento. But for first time (never before) visitors we could serve a cached almost static ready to send version?
Question: can we distinguish complete new vs. return visitors in Nginx? And how would we then serve a static file to the complete new visitors (frontpage + categories + cms + products)
General conf
fastcgi_cache_path /var/run/nginx-cache levels=1:2 keys_zone=MAGENTO:100m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
fastcgi_cache_use_stale error timeout invalid_header http_500;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
Server block
# CACHE TEST
set $skip_cache 0;
# CACHE TEST
if ($http_cookie ~* "frontend_cid|frontend|sid|adminhtml") {
set $skip_cache 1;
}
# CACHE TEST
if ($request_method = POST) {
set $skip_cache 1;
}
# CACHE TEST
if ($query_string != "") {
set $skip_cache 1;
}
## Execute PHP scripts
location ~ .php$ {
include /etc/nginx/conf.d/headers.conf;
add_header Strict-Transport-Security "max-age=31556926; includeSubDomains; preload";
try_files $uri =404;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param MAGE_RUN_CODE $storecode;
fastcgi_param MAGE_RUN_TYPE store;
include fastcgi_params;
# CACHE TEST
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
fastcgi_cache MAGENTO;
fastcgi_cache_valid 60m;
}
cache full-page-cache nginx server-setup
bumped to the homepage by Community♦ 11 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
In an effort (and test) to make Magento fly I was playing with microcaching in Magento and came up with the following.
The idea is to: detect a first visit and return visit. A return visit may already have an item in the cart or some session params so we need the dynamic full (slow) Magento. But for first time (never before) visitors we could serve a cached almost static ready to send version?
Question: can we distinguish complete new vs. return visitors in Nginx? And how would we then serve a static file to the complete new visitors (frontpage + categories + cms + products)
General conf
fastcgi_cache_path /var/run/nginx-cache levels=1:2 keys_zone=MAGENTO:100m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
fastcgi_cache_use_stale error timeout invalid_header http_500;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
Server block
# CACHE TEST
set $skip_cache 0;
# CACHE TEST
if ($http_cookie ~* "frontend_cid|frontend|sid|adminhtml") {
set $skip_cache 1;
}
# CACHE TEST
if ($request_method = POST) {
set $skip_cache 1;
}
# CACHE TEST
if ($query_string != "") {
set $skip_cache 1;
}
## Execute PHP scripts
location ~ .php$ {
include /etc/nginx/conf.d/headers.conf;
add_header Strict-Transport-Security "max-age=31556926; includeSubDomains; preload";
try_files $uri =404;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param MAGE_RUN_CODE $storecode;
fastcgi_param MAGE_RUN_TYPE store;
include fastcgi_params;
# CACHE TEST
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
fastcgi_cache MAGENTO;
fastcgi_cache_valid 60m;
}
cache full-page-cache nginx server-setup
bumped to the homepage by Community♦ 11 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
hm, varnish is much better for this.
– MagenX
Apr 15 '17 at 9:55
add a comment |
In an effort (and test) to make Magento fly I was playing with microcaching in Magento and came up with the following.
The idea is to: detect a first visit and return visit. A return visit may already have an item in the cart or some session params so we need the dynamic full (slow) Magento. But for first time (never before) visitors we could serve a cached almost static ready to send version?
Question: can we distinguish complete new vs. return visitors in Nginx? And how would we then serve a static file to the complete new visitors (frontpage + categories + cms + products)
General conf
fastcgi_cache_path /var/run/nginx-cache levels=1:2 keys_zone=MAGENTO:100m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
fastcgi_cache_use_stale error timeout invalid_header http_500;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
Server block
# CACHE TEST
set $skip_cache 0;
# CACHE TEST
if ($http_cookie ~* "frontend_cid|frontend|sid|adminhtml") {
set $skip_cache 1;
}
# CACHE TEST
if ($request_method = POST) {
set $skip_cache 1;
}
# CACHE TEST
if ($query_string != "") {
set $skip_cache 1;
}
## Execute PHP scripts
location ~ .php$ {
include /etc/nginx/conf.d/headers.conf;
add_header Strict-Transport-Security "max-age=31556926; includeSubDomains; preload";
try_files $uri =404;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param MAGE_RUN_CODE $storecode;
fastcgi_param MAGE_RUN_TYPE store;
include fastcgi_params;
# CACHE TEST
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
fastcgi_cache MAGENTO;
fastcgi_cache_valid 60m;
}
cache full-page-cache nginx server-setup
In an effort (and test) to make Magento fly I was playing with microcaching in Magento and came up with the following.
The idea is to: detect a first visit and return visit. A return visit may already have an item in the cart or some session params so we need the dynamic full (slow) Magento. But for first time (never before) visitors we could serve a cached almost static ready to send version?
Question: can we distinguish complete new vs. return visitors in Nginx? And how would we then serve a static file to the complete new visitors (frontpage + categories + cms + products)
General conf
fastcgi_cache_path /var/run/nginx-cache levels=1:2 keys_zone=MAGENTO:100m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
fastcgi_cache_use_stale error timeout invalid_header http_500;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
Server block
# CACHE TEST
set $skip_cache 0;
# CACHE TEST
if ($http_cookie ~* "frontend_cid|frontend|sid|adminhtml") {
set $skip_cache 1;
}
# CACHE TEST
if ($request_method = POST) {
set $skip_cache 1;
}
# CACHE TEST
if ($query_string != "") {
set $skip_cache 1;
}
## Execute PHP scripts
location ~ .php$ {
include /etc/nginx/conf.d/headers.conf;
add_header Strict-Transport-Security "max-age=31556926; includeSubDomains; preload";
try_files $uri =404;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param MAGE_RUN_CODE $storecode;
fastcgi_param MAGE_RUN_TYPE store;
include fastcgi_params;
# CACHE TEST
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
fastcgi_cache MAGENTO;
fastcgi_cache_valid 60m;
}
cache full-page-cache nginx server-setup
cache full-page-cache nginx server-setup
asked Jan 11 '17 at 20:17
snh_nlsnh_nl
2,9031046105
2,9031046105
bumped to the homepage by Community♦ 11 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 11 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
hm, varnish is much better for this.
– MagenX
Apr 15 '17 at 9:55
add a comment |
hm, varnish is much better for this.
– MagenX
Apr 15 '17 at 9:55
hm, varnish is much better for this.
– MagenX
Apr 15 '17 at 9:55
hm, varnish is much better for this.
– MagenX
Apr 15 '17 at 9:55
add a comment |
1 Answer
1
active
oldest
votes
Unfortunately, the answer is "you can't".
Magento 1.x will always set the frontend
cookie, and outside application level (Nginx, Varnish, etc.) you can't know whether it is a new visit or not.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f154326%2fmagento-nginx-cache-first-page-request-only-no-session-for-super-speed%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Unfortunately, the answer is "you can't".
Magento 1.x will always set the frontend
cookie, and outside application level (Nginx, Varnish, etc.) you can't know whether it is a new visit or not.
add a comment |
Unfortunately, the answer is "you can't".
Magento 1.x will always set the frontend
cookie, and outside application level (Nginx, Varnish, etc.) you can't know whether it is a new visit or not.
add a comment |
Unfortunately, the answer is "you can't".
Magento 1.x will always set the frontend
cookie, and outside application level (Nginx, Varnish, etc.) you can't know whether it is a new visit or not.
Unfortunately, the answer is "you can't".
Magento 1.x will always set the frontend
cookie, and outside application level (Nginx, Varnish, etc.) you can't know whether it is a new visit or not.
answered Apr 8 '17 at 19:56
Danila VershininDanila Vershinin
41227
41227
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f154326%2fmagento-nginx-cache-first-page-request-only-no-session-for-super-speed%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
hm, varnish is much better for this.
– MagenX
Apr 15 '17 at 9:55