Welcome! Log In Create A New Profile


FastCGI + Cart for OpenCart 2.x

Posted by WebFlyer 
FastCGI + Cart for OpenCart 2.x
November 21, 2019 03:07PM
Hello all,
Need to help with such thing.
My partner's shop built with OpenCart 2.2.
It was Toooo slow on Apache. I move it onto nginx+fastcgi.
Result is excellent, but... cart have cached too. And dropped while user changes a page.

My config (from sites.available
$cat /etc/nginx/sites-available/vps1.conf

fastcgi_cache_path /var/www/cache/vps1 levels=1:2 keys_zone=vps1:1000m inactive=168h;
fastcgi_cache_key "$scheme$request_method$host$request_uri";

# Expires map
map $sent_http_content_type $expires {
default off;
text/html epoch;
text/css max;
application/javascript max;
~image/ max;

server {
root /var/www/vps1/html/;
index index.php index.html;
server_name vps1.com.ct;
error_log /var/log/nginx/vps1_error.log;
access_log /var/log/nginx/vps1_access.log;

expires $expires;

location /image/data {
autoindex on;

location /admin {
index index.php;

location / {
try_files $uri @opencart;

location @opencart {
rewrite ^/(.+)$ /index.php?_route_=$1 last;

location ~* \.(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(\..*|Entries.*|Repository|Root|Tag|Template)$|\.php_ {
deny all;

location ~ /\. {
deny all;
access_log off;
log_not_found off;

location ~* \.(jpg|jpeg|png|gif|css|js|ico)$ {
expires max;
log_not_found off;

# Fastcgi cache rules
include snippets/fastcgi-cache.conf;
include snippets/limits.conf;
location ~ \.php$ {
try_files $uri =404;
include snippets/fastcgi-params.conf;
fastcgi_pass unix:/run/php/php7.3-fpm.sock;
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
fastcgi_cache vps1;
fastcgi_cache_valid 168h;

fastcgi_read_timeout 6000;
fastcgi_connect_timeout 6000;
fastcgi_send_timeout 6000;
proxy_read_timeout 6000;
proxy_connect_timeout 6000;
proxy_send_timeout 6000;
send_timeout 6000;

cat /etc/nginx/snippets/fastcgi-cache.conf

# The key to use when saving cache files, which will run through the MD5 hashing algorithm.
fastcgi_cache_key "$scheme$request_method$host$request_uri";

# If an error occurs when communicating with FastCGI server, return cached content.
# Useful for serving cached content if the PHP process dies or timeouts.
fastcgi_cache_use_stale error timeout invalid_header http_500;

# Allow caching of requests which contain the following headers.
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;

### Answer STALE and update cache
fastcgi_cache_use_stale updating;
fastcgi_cache_background_update on;

# Show the cache status in server responses.
add_header Fastcgi-Cache $upstream_cache_status;

# Don't skip by default
set $skip_cache 0;

# POST requests and urls with a query string should always go to PHP
if ($request_method = POST) {
set $skip_cache 1;

if ($query_string != "") {
set $skip_cache 1;


I suppose that ESI might be a solution. But I cannot find exitsted one...
Thanls a lot for help and advise.

Edited 1 time(s). Last edit at 11/21/2019 03:10PM by WebFlyer.
Re: FastCGI + Cart for OpenCart 2.x
January 03, 2022 10:46AM
Hi WebFlyer,

Did you get any solution o this problem.
I'am facing the same problem.

Please reply
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 86
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready