How to configure varnish and Magento 2
2 min readJun 28, 2021
step1 : install varnish
apt install -y varnish
varnishd -V
step2 : change nginx port and varnish port
- nginx port:
/etc/nginx/sites-avaiable
server{ listen 8080;}
check: netstat -tulpn
- varnish port:
/etc/default/varnish
DAEMON_OPTS=”-a :80 \
-T localhost:6082 \
-f /etc/varnish/default.vcl \
-S /etc/varnish/secret \
-s malloc,256m”
VARNISH_LISTEN_PORT=80
varnish 5:/lib/systemd/system/varnish.service
varnish 6: /etc/systemd/system/varnish.service.d/customexec.conf
verify varnish port
step 3: configure magento and varnish
download varnish config file from magento admin
fixed:
“Tip “: error 503 backend fetch failed varnish
.probe = {
.url = "/pub/health_check.php";
change it to
.probe = {
.url = "/health_check.php";
step4: set varnish purge with magento cache clear
bin/magento config:set system/full_page_cache/caching_application 2
bin/magento setup:config:set --http-cache-hosts=192.168.00.00:80
curl -v -X PURGE -H ‘X-Magento-Tags-Pattern: .*’ http://dev.jtcmetals.com/