cancel
Showing results for 
Search instead for 
Did you mean: 

Facing issue in varnish configuration

   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

Facing issue in varnish configuration

I have installed the varnish on the server successfully.

Now I want to configure it with Magento 2

 

Please find the current values of all files below.

 

Server IP: 4.1.173.181

 

Magento 2 Admin:

Stores > Configuration > ADVANCED > System > Full Page Cache

Caching Application: Varnish Cache (Recommended)

 

Varnish Configuration:
    Access list: 4.1.173.181
    Backend Host: 4.1.173.181
    Backend Port: 8080

 

/etc/varnish/default.vcl

 

 

#
# This is an example VCL file for Varnish.
#
# It does not do anything by default, delegating control to the
# builtin VCL. The builtin VCL is called when there is no explicit
# return statement.
#
# See the VCL chapters in the Users Guide at https://www.varnish-cache.org/docs/
# and http://varnish-cache.org/trac/wiki/VCLExamples for more examples.

# Marker to tell the VCL compiler that this VCL has been adapted to the
# new 4.0 format.
vcl 4.0;

# Default backend definition. Set this to point to your content server.
backend default {
.host = "4.1.173.181";
.port = "8080";
}

sub vcl_recv {
# Happens before we check if we have this in cache already.
#
# Typically you clean up the request here, removing cookies you don't need,
# rewriting the request, etc.
}

sub vcl_backend_response {
# Happens after we have read the response headers from the backend.
#
# Here you clean the response headers, removing silly Set-Cookie headers
# and other mistakes your backend does.
}

sub vcl_deliver {
# Happens when we have all the pieces we need, and are about to send the
# response to the client.
#
# You can do accounting or modifying the final object here.
}

 


/etc/varnish/varnish.params

 

 

# Varnish environment configuration description. This was derived from
# the old style sysconfig/defaults settings

# Set this to 1 to make systemd reload try to switch VCL without restart.
RELOAD_VCL=1

# Main configuration file. You probably want to change it.
VARNISH_VCL_CONF=/etc/varnish/default.vcl

# Default address and port to bind to. Blank address means all IPv4
# and IPv6 interfaces, otherwise specify a host name, an IPv4 dotted
# quad, or an IPv6 address in brackets.
# VARNISH_LISTEN_ADDRESS=192.168.1.5
# VARNISH_LISTEN_PORT=6081
VARNISH_LISTEN_PORT=8080

# Admin interface listen address and port
# VARNISH_ADMIN_LISTEN_ADDRESS=127.0.0.1
# VARNISH_ADMIN_LISTEN_PORT=6082
VARNISH_ADMIN_LISTEN_ADDRESS=4.1.173.181
VARNISH_ADMIN_LISTEN_PORT=8080

# Shared secret file for admin interface
VARNISH_SECRET_FILE=/etc/varnish/secret

# Backend storage specification, see Storage Types in the varnishd(5)
# man page for details.
VARNISH_STORAGE="malloc,256M"

# User and group for the varnishd worker processes
VARNISH_USER=varnish
VARNISH_GROUP=varnish

# Other options, see the man page varnishd(1)
#DAEMON_OPTS="-p thread_pool_min=5 -p thread_pool_max=500 -p thread_pool_timeout=300"

 

 

/magento2/app/etc/env.php

 

 

'http_cache_hosts' => 
array (
0 => 
array (
'host' => '4.1.173.181',
'port' => '8080',
),
),

 


But when I run the following command to check if varnish is enabled or not, it doesn't show X-varnish in the response header. It seems that varnish is not configured with Magento 2 properly.

 

 

curl -I -v --location-trusted 'http://4.1.173.181/magento2'

 

 

Am I doing anything wrong?

Please help.

If you find my answer useful, Please click Kudos & Accept as Solution.