How to install Varnish cache and configure Magento 2 to use Varnish cache on Ubuntu

► Fanpage: / giaphugroupcom
► Subscribe to my channel: kzread.info...
► Skype: cuongnq87
► The website link: www.giaphugroup.com/magento-2...
Hi everybody, I am Cuong, Welcome back to my Magento 2 tutorial video series.
#magento #magento2 #magento2tutorial #varnishcache
In the previous lesson, I showed everybody on How to install Redis and configure Magento to use Redis for session storage on Ubuntu. If you don't watch this tutorial yet, you can watch it here bit.ly/3u3ZhBj. This practice I mentioned to the Varnish cache and Magento recommends using it.
To continue the exercises are related to improving website performance. Today, I am going to show everybody on How to install Varnish cache and configure Magento 2 to use Varnish cache on Ubuntu.
I have the domains phpmyadmin.giaphugroup.com and giaphugroup.com on my server. It is not using Varnish cache.
Okie, let's go.
Let's do this practice, you need to follow steps by step:
Step 1: Install Varnish cache on Ubuntu.
- cat /etc/*release
I have Ubuntu 18.04 on my server.
- Install Varnish cache
apt-get install varnish
- Verify that Varnish cache is running on your server
1. service varnish status
2. varnishd -V
3. Check the port is used for Varnish
netstat -plnt
I installed the Varnish cache to succeed.
Step 2: Configure Nginx
1. nginx -v
2. By default, Nginx runs on port 80, so we will need to configure the Nginx to listen on port 8088. The port 80 will be used for Varnish cache.
- nano /etc/nginx/sites-available/default, Change the default port from 80 to 8088.
- Then update all domains on your server to listen on port 8088.
I have phpmyadmin.giaphugroup.com and giaphugroup.com on my server. So I need to update the Nginx virtual host configuration file of these domains.
nano /etc/nginx/sites-available/phpmyadmin
nano /etc/nginx/sites-available/giaphugroup.com
3. Configure the domains to handle HTTPS requests and forward everything to default Varnish port.
- nano /etc/nginx/sites-available/phpmyadmin
proxy_pass 127.0.0.1/;
proxy_set_header Host $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-Port 443;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-Ssl on;
- nano /etc/nginx/sites-available/giaphugroup.com
- Create the new file nginx.conf having the content is copied from nginx.conf.sample. Then add the following codes to location / {}
proxy_pass 127.0.0.1/;
proxy_set_header Host $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-Port 443;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-Ssl on;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
fastcgi_buffer_size 32k;
fastcgi_buffers 4 32k;
4. systemctl restart nginx
Step 3: Configure Varnish Cache
1. We will need to configure Varnish to use port 80 so it can route traffic to the Nginx web server via the Varnish cache server.
2. We can do it by editing the file /lib/systemd/system/varnish.service:
nano /lib/systemd/system/varnish.service
Change the Varnish default port from 6081 to 80
3. systemctl daemon-reload
4. nano /etc/varnish/default.vcl and Change the port from 8080 to 8088
5. systemctl restart varnish
Step 4: Configure Magento to use Varnish cache
1. Go to the backend and navigate to STORES - Configuration - Advanced - System - Full Page Cache
2. Set the field named Caching Application to "Varnish Cache (Recommended)"
3. Set the field named Access list to 127.0.0.1
4. Set the field named Backend host to 127.0.0.1
5. Set the field named Backend port to 8088
Step 5: Test and See the result
1. You can check the Varnish cache with the curl command as shown below:
curl -I your-server-ip
2. Check the logs
varnishncsa or varnishlog
- Try to use a web browser for accessing to your website and checking.
3. You can also verify Varnish caching statistics with the following command:
varnishstat
4. You also can check the Varnish cache by using F12
Yeah! It works perfectly.
Thank you for your watching. If you have any questions about this practice, please feel free to leave a comment below.
Don't forget to like, comment, share my videos and subscribe to my channel for getting the latest videos.
Please do not hesitate to contact me, if you need me to join your Magento project. My rate is $25/hour in Magento 1 and $30/hour in Magento 2.

Пікірлер: 20

  • @Magento2Tutorial
    @Magento2Tutorial3 жыл бұрын

    Please help me to reach 10.000 subscribers by subscribing to my channel and sharing my videos.

  • @enggarshad83

    @enggarshad83

    3 жыл бұрын

    nice video, shared in telegram magento2 channels

  • @sajidwaseemal-arfeen5144
    @sajidwaseemal-arfeen51443 жыл бұрын

    very nice

  • @anguraj7502
    @anguraj75022 жыл бұрын

    Hello Your video are too good and I have a question for you. After the steps it's working and I've deployed the sample data and no change in website. Then I disable the varnish and reroute it . After website working with proper format with images. Kindly help me to fix

  • @akmaris84
    @akmaris842 жыл бұрын

    Do you have any tutorial for elb, varnish, nginx, Magento configuration?

  • @singowl2833
    @singowl28333 жыл бұрын

    thank you ,it's amazing! My question: Does the M2.3.6 surport varnish 6.x? I have follew you step by step,but it not work on SSL, display 500 error. WHAT happend?

  • @Magento2Tutorial

    @Magento2Tutorial

    3 жыл бұрын

    Can you show me the content of nginx.conf and /etc/varnish/default.vcl on your website? Maybe you exported the varnish.vcl file from Magento backend? this is the cause.

  • @singowl2833

    @singowl2833

    3 жыл бұрын

    @@Magento2Tutorial yes ,you are right.the default.vcl is created by magneto backend.

  • @Magento2Tutorial

    @Magento2Tutorial

    3 жыл бұрын

    @@singowl2833 Follow my video, I don't use this file of Magento 2 backend. It is the cause making the issue 500

  • @ahmedalmulki

    @ahmedalmulki

    3 жыл бұрын

    did you find a solution for your problem please?

  • @anshbhatia3524
    @anshbhatia35243 жыл бұрын

    Hello sir my magento2 website is running on ubuntu ec2 with amazon SSL can i follow same steps for setup varnish cache?

  • @Magento2Tutorial

    @Magento2Tutorial

    3 жыл бұрын

    In this video, I shown you how I installed Varnish cache and configure it using on ubuntu

  • @markben2959
    @markben29592 жыл бұрын

    Please we need another tutorial with apache

  • @Magento2Tutorial

    @Magento2Tutorial

    2 жыл бұрын

    I will create and send you the link ASAP

  • @ericcrowther9812

    @ericcrowther9812

    2 жыл бұрын

    @@Magento2Tutorial please send me link as well

  • @mayankpatel3181

    @mayankpatel3181

    2 жыл бұрын

    @@Magento2Tutorial did you created video for apache? Please send me link.

  • @pavinisharma7940
    @pavinisharma79403 жыл бұрын

    its not working, you have not used magento generated vcl file. kindly upload the correct video

  • @Magento2Tutorial

    @Magento2Tutorial

    3 жыл бұрын

    Don't use default.vcl that you exported from Magento 2, this is the cause makes the issue. In my video, I don't use this file.

  • @12uzair
    @12uzair3 ай бұрын

    Can you share your vcl?

  • @Magento2Tutorial

    @Magento2Tutorial

    Күн бұрын

    vcl in the description of this video.