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

    set $skip_cache 0;

    if ($http_cookie ~* "frontend_cid|frontend|sid|adminhtml") {
     set $skip_cache 1;

    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_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;
  • hm, varnish is much better for this.
    – MagenX
    Apr 15, 2017 at 9:55

1 Answer 1


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.