736Online Posted July 20, 2015 Share Posted July 20, 2015 I apologize in advance if somethings aren't clear, I'm learning how to edit server settings as I go so I'm not versed on how to put a lot of things. If you have any questions or need clarity anywhere just ask and I'll do my best to provide the details needed to get this issue resolved for myself or anyone else in the community that may have/will come across this problem. From testing I have confirmed that cache is the root cause of this problem as I have deactivated it on one site on the server and the problem goes away and the other still has it. My sites are loading in at incredible speeds compared to how they were before adding the cache settings, but the cache is caching user information, keeping the cart from saving, and disabling my instant search results. For example I can log in with my test account and try to logout it just refreshes the page and shows my user information still at the top. If I add something to my cart and then go to the cart it will be empty or if I add from the home page and then go to the cart and back again my cart will show as 0 again. I've seen that when you're running just Apache you can add: "ExpiresByType text/html "access plus 0 minutes"" to get rid of the caching issues that are similar to this. I have added the below code to stop the admin/order/account/login pages from being cached: set $no_cache 0; if ($request_uri ~* "/(admin8909/|order|my-account|login|cart|order)"){ set $no_cache 1;} With this in place I am able go to the login page > login and be directed to my-account > from my-account page can I can actually logout and be directed back to login screen...every other page is just a refresh of the same page, but if I hit logout from those pages and try to go back to my-account I am in fact logged out. I am also able to travel to every page except the ones that I visited before I logged in and be logged in. Is there a way to have ajax bypassed by the caching and have user sessions, cart, and search results all passed via ajax to verify the current user? PM Me and I can give you a site link. I don't mind experimenting and breaking things to get this figured out as this is a fresh install, I just need it fixed so that my other live site can benefit from the speed and I can then get this site online as well. Link to comment Share on other sites More sharing options...
736Online Posted July 20, 2015 Author Share Posted July 20, 2015 Correction, the search does in fact work properly. Link to comment Share on other sites More sharing options...
736Online Posted July 20, 2015 Author Share Posted July 20, 2015 For details sake, one site is using 1.6.1.0 and the other 1.6.0.14 Link to comment Share on other sites More sharing options...
DanielLozano2 Posted July 21, 2015 Share Posted July 21, 2015 Maybe try to enable (on Prestashop) Advanced Params. < Webservices < CGI for PHP (I dont know if it will work but it cant break anything) 1 Link to comment Share on other sites More sharing options...
736Online Posted July 21, 2015 Author Share Posted July 21, 2015 Hey Daniel, Thanks for the advice, I read up on that feature and the docs say that it is for when you're running on an apache server and I'm on nginx. I found an article about a similar problem on a wordpress site and the suggested solution was to add the cookie to the fastcgi_cache_key but I haven't been able to get that to work. Here's the article: http://community.rtcamp.com/t/prevent-fastcgi-cache-from-caching-specific-functions-or-wp-shortcodes/2506 Link to comment Share on other sites More sharing options...
DanielLozano2 Posted July 21, 2015 Share Posted July 21, 2015 I got it working right now, but it seems to have some bugs. If you want i cant provide you my nginx config. (Maybe you need to clean the cache and reload nginx) Link to comment Share on other sites More sharing options...
736Online Posted July 21, 2015 Author Share Posted July 21, 2015 Yes, please provide it so I can check it out. I have cleared my cache, reset the server and did everything from scratch a few times. Link to comment Share on other sites More sharing options...
DanielLozano2 Posted July 21, 2015 Share Posted July 21, 2015 # here you select your cache path and the name (MYAPP) to id your cache fastcgi_cache_path /etc/nginx/cache levels=1:2 keys_zone=MYAPP:100m inactive=60m; # here you select the key to id. your cache elements. fastcgi_cache_key "$scheme$request_method$host$request_uri$cookie_state"; server { # virtualhost settings... listen 80 default_server; listen [::]:80 default_server ipv6only=on; server_name localhost; # directory and logs settings... root /var/www/yourhost.com/public_html; access_log /var/www/yourhost.com/logs/access.log; error_log /var/www/yourhost.com/logs/error.log; index index.php; # maybe you want to add http authentication #auth_basic "Restricted"; #auth_basic_user_file /etc/nginx/.htpasswd; ## # Prestashop Rewrites ## rewrite ^/api/?(.*)$ /webservice/dispatcher.php?url=$1 last; rewrite ^/([0-9])(-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*.jpg$ /img/p/$1/$1$2.jpg last; rewrite ^/([0-9])([0-9])(-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*.jpg$ /img/p/$1/$2/$1$2$3.jpg last; rewrite ^/([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*.jpg$ /img/p/$1/$2/$3/$1$2$3$4.jpg last; rewrite ^/([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*.jpg$ /img/p/$1/$2/$3/$4/$1$2$3$4$5.jpg last; rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*.jpg$ /img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6.jpg last; rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7.jpg last; rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8.jpg last; rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9.jpg last; rewrite ^/c/([0-9]+)(-[_a-zA-Z0-9-]*)/[_a-zA-Z0-9-]*.jpg$ /img/c/$1$2.jpg last; rewrite ^/c/([a-zA-Z-]+)/[a-zA-Z0-9-]+.jpg$ /img/c/$1.jpg last; rewrite ^/([0-9]+)(-[_a-zA-Z0-9-]*)/[_a-zA-Z0-9-]*.jpg$ /img/c/$1$2.jpg last; try_files $uri $uri/ /index.php?$args; # cache with nginx the static files location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ { expires 30d; access_log off; add_header Cache-Control "public"; } location ~* \.(?:manifest|appcache|html?|xml|json)$ { expires -1; # access_log logs/static.log; # I don't usually include a static log } # cache with nginx more static files location ~* \.(?:css|js)$ { expires max; access_log off; add_header Cache-Control "public"; } # and here fastcgi config location ~ \.php { fastcgi_index index.php; fastcgi_cache MYAPP; # http code that u will cache, and the time it will be cached fastcgi_cache_valid 200 60m; fastcgi_split_path_info ^(.+\.php)(.*)$; include /etc/nginx/fastcgi_params; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } # wordpress (maybe you have nested apps in your app) location /blog { index index.php index.html; try_files $uri $uri/ /blog/index.php?$args; } # gzip compression gzip on; gzip_proxied any; gzip_types text/css text/plain text/javascript application/javascript application/json application/x-javascript application/xml application/xml+rss application/xhtml+xml application/x-font-ttf application/x-font-opentype application/vnd.ms-fontobject image/svg+xml image/x-icon application/rss+xml application/atom_xml; gzip_comp_level 9; gzip_http_version 1.0; gzip_buffers 16 8k; gzip_min_length 50; } I think i didn't forget anything. What I might do is try to cache everything, and then go for the cookie exceptions. 1 Link to comment Share on other sites More sharing options...
736Online Posted July 21, 2015 Author Share Posted July 21, 2015 Have you been able to verify that your server is caching everything? Can you create and upload a file called test-time.php with this inside: <?php echo time(); ?> If you refresh this a few times the time should stay the same. Let me know if it works for you. Link to comment Share on other sites More sharing options...
DanielLozano2 Posted July 21, 2015 Share Posted July 21, 2015 I attach you 3 images, 1 without cache and then 2 with cache. 1 Link to comment Share on other sites More sharing options...
736Online Posted July 21, 2015 Author Share Posted July 21, 2015 I changed my code to match yours and I'm now able to go from page to page as the logged in user BUT the user session is being cached so I can log in incognito mode on Chrome and be logged in a the user who was on the normal browser. The below code should be what handles that, correct? location ~* \.(?:manifest|appcache|html?|xml|json)$ { expires -1;# access_log logs/static.log; # I don't usually include a static log} Link to comment Share on other sites More sharing options...
PhilCorleone Posted July 21, 2015 Share Posted July 21, 2015 I wish I could help you out but i'm starting to learn how to deal with NGinx and Apache the past month and i'm still doing so. I'm greatful for all of your info here guys as they will help me out in my learning curve. Link to comment Share on other sites More sharing options...
736Online Posted July 21, 2015 Author Share Posted July 21, 2015 (edited) Thanks for at least looking, Phil! I've done a lot of research and have been able to get my websites extremely fast when cached, but this cookie/session issue is really throwing me in circles! Is it possible to exclude a tpl file from a cache? Edited July 21, 2015 by 736Online (see edit history) Link to comment Share on other sites More sharing options...
PhilCorleone Posted July 21, 2015 Share Posted July 21, 2015 Yeah, I mean 143 milliseconds. That's like light years. That's why i'm starting to learn how to deal with NGINX. fr the tpl file, i'm not sure though, you seem pretty advanced into the caching subject by now. When i get free soon, I will research it with you. 1 Link to comment Share on other sites More sharing options...
736Online Posted July 21, 2015 Author Share Posted July 21, 2015 Yeah, I mean 143 milliseconds. That's like light years. That's why i'm starting to learn how to deal with NGINX. fr the tpl file, i'm not sure though, you seem pretty advanced into the caching subject by now. When i get free soon, I will research it with you. Thank you! We'll talk soon Link to comment Share on other sites More sharing options...
736Online Posted July 21, 2015 Author Share Posted July 21, 2015 I attach you 3 images, 1 without cache and then 2 with cache. Do you have any special rules for cookies set up anywhere that's not included in the code you attached? Link to comment Share on other sites More sharing options...
PhilCorleone Posted July 21, 2015 Share Posted July 21, 2015 I got a linux server setup as a learning environment. I'm waiting for the weekend to come then we will hit this all. I need to be caught up with what you have though. What is your timezone by the way? i'm -5 GMT eastern time. Link to comment Share on other sites More sharing options...
736Online Posted July 22, 2015 Author Share Posted July 22, 2015 I'm on eastern time as well, I'll keep hacking away at this and will report anything I figure out so that everyone can learn/benefit from it. Link to comment Share on other sites More sharing options...
736Online Posted July 22, 2015 Author Share Posted July 22, 2015 I got it working right now, but it seems to have some bugs. If you want i cant provide you my nginx config. (Maybe you need to clean the cache and reload nginx) What version of nginx are you running? Link to comment Share on other sites More sharing options...
DanielLozano2 Posted July 22, 2015 Share Posted July 22, 2015 This is the problem with fastcgi-cache and varnish, they cache the response, so if you need to work this response with cookies (user logged, cart, wishlist...) you need extra-work, for example making the proccess via ajax (post request) and its not cached and you dont lose the speed of the cache. Link to comment Share on other sites More sharing options...
736Online Posted July 22, 2015 Author Share Posted July 22, 2015 Have you already implemented ajax for user logged? My original thought was to use cookie value to track everything and second was ajax but wasn't sure if ajax would work with the cookie issue still in place. Link to comment Share on other sites More sharing options...
DanielLozano Posted July 22, 2015 Share Posted July 22, 2015 No sorry, I've been looking for a good solution to implement http caches to eCommerces like Prestashop but I have not a solution jet. You need something to save the actual state of the app. If you move from fastcgi to Varnish cache you could read about ESI Includes (you can cache part of the page), but prestashop and almost any framework or eCommerce are ready to implement then.... So im really sorry D:, even if you use ajax for user data, you need to store the Cart.. (maybe in a html5 local storage in the client side....) If you find a solution please, share it!!! Link to comment Share on other sites More sharing options...
carras Posted August 26, 2015 Share Posted August 26, 2015 # here you select your cache path and the name (MYAPP) to id your cache fastcgi_cache_path /etc/nginx/cache levels=1:2 keys_zone=MYAPP:100m inactive=60m; # here you select the key to id. your cache elements. fastcgi_cache_key "$scheme$request_method$host$request_uri$cookie_state"; server { Using your FastCGI Cache configuration my site doesn't work properly. For example, you add some product to the cart and the cart doesn't change because te whole page is in the cache. How do you manage to solve that issue? With exceptions like this one?: #Don't cache the following URLs if ($request_uri ~* "/(administrator/|login.php)") { set $no_cache 1; } Link to comment Share on other sites More sharing options...
carras Posted October 15, 2015 Share Posted October 15, 2015 Hi, So, does any of you have FastCgi Cache on a PS site? Cuz I tried before and, as some of you say, the logged in user it's unable to add product to the cart and all that stuff. Thanks. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now