Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Server side optimization with Magento-Redis+Varnish+Nginx

How to speed up a Magento site? How to optimize Magento platform ?

You might have already come across the common tips like;

  • Latest Magento Version
  • CDN
  • Image optimization
  • Magento Cache management
  • Page caching extensions
  • Combine CSS and JS files
  • Reducing HTTP requests

You will definitely see performance improvement once the above tweaks are applied. But that is not the end of what a System Admin can do to make your website faster.

Welcome to the world of Magento Server Side Optimization

1.Cache backend and Session storage

By default, Magento stores it’s Cache entries in the file system. That is fine with low traffic websites. But read/writes will become an overhead, if you expect high traffic on your magento store, as the cache grows from time to time.

The options we have are to use APC, MemCache or Redis for the cache.

I would recommend Redis, as it is a very fast cache backend with full cache tag support, and therefore no slow level file system cache is needed and better in terms of memory usage as well.

Install Redis

We should install/enable EPEL repo and get Redis server installed and configured


#rpm -Uvh epel-release-6*.rpm

#rpm --import

#yum install redis

#chkconfig redis on

#service redis start

#service httpd restart

The integration between Redis and Magento is already done in Magento CE 1.8 and EE 1.13 and later versions, it just need to be configured.

To configure Magento to use Redis

  • Enable the Cm_RedisSession module
  • In app/etc/modules/Cm_RedisSession.xml change the value of active to true
  • In app/etc/local.xml make the below changes















           1 0 used as persistence ID –>



  • Flush the Magento cache

2.Full Page cache

Varnish is a web application accelerator, which can work as a load balancer and caching reverse proxy. If cached in Varnish it will reduce the load time significantly as the cached page is served directly from RAM. Varnish can serve static content faster even when there is high traffic on the website. But to serve dynamic content Varnish is not a good choice as it fetches the content from the backend server, and we have to deal with SSL as well.

Varnish+Nginx would be the best choice here as Varnish doesn’t support SSL connections. Nginx is used to handle SSL termination and HTTPS redirection.

Install Nginx

Install Nginx, and configure the domain’s configuration file. A sample entry will look like;

upstream fastcgi_backend {
server unix:/run/php/php7.1-fpm.sock;

server { server_name; listen 80; set $MAGE_ROOT /var/www/; set $MAGE_MODE developer; # developer/production

access_log /var/log/nginx/; error_log /var/log/nginx/;

include /var/www/; }

Enable and Start Nginx Server

#systemctl enable nginx
#service nginx start

Install Varnish

We have already enabled EPEL repo in the first step. So just use yum to install varnish.

#yum install varnish

From Magento Admin dashboard set Varnish Cache as Full Page Cache and export the VCL.

Configuration -> ADVANCED -> System -> Full Page Cache

Replace the /etc/varnish/default.vcl file with the contents of exported VCL.

By default Varnish listens on port 6081

Change VARNISH_LISTEN_PORT from 6081 to 80, in /etc/varnish/varnish.params

In /etc/varnish/default.vcl tell Varnish to get the content on port 8080.

backend default {
.host = “”;
.port = “8080”;

Configure Nginx for SSL termination

Change Nginx listening port from 80 to 8080 and enable Nginx SSL termination with HTTP2

upstream fastcgi_backend {
server unix:/run/php/php7.1-fpm.sock;

server { server_name; listen 8080; set $MAGE_ROOT /var/www/; set $MAGE_MODE developer; # developer/production

access_log /var/log/nginx/; error_log /var/log/nginx/;

include /var/www/; }

server {

listen 443 ssl http2; server_name;

ssl_certificate /etc/ssl/certs/; # Domain’s ssl cert ssl_certificate_key /etc/ssl/private/; # Domain’s ssl key ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers ‘AES128+EECDH:AES128+EDH:!aNULL’; ssl_session_cache shared:SSL:10m; ssl_session_timeout 24h; keepalive_timeout 300s;

location / { proxy_pass; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Ssl-Offloaded “1”; proxy_set_header X-Forwarded-Proto https; Proxy_set_header X-Forwarded-Port 443; #proxy_hide_header X-Varnish; #proxy_hide_header Via; proxy_set_header X-Forwarded-Proto $scheme;


Next, you have to restart Nginx and Varnish.

That’s it! Now you have a faster Magento website!!

The post Server side optimization with Magento-Redis+Varnish+Nginx appeared first on Sysally.

This post first appeared on Make IT Work - A Complete Solutions For IT Professionals, please read the originial post: here

Share the post

Server side optimization with Magento-Redis+Varnish+Nginx


Subscribe to Make It Work - A Complete Solutions For It Professionals

Get updates delivered right to your inbox!

Thank you for your subscription