{"id":3538,"date":"2019-02-08T02:36:14","date_gmt":"2019-02-08T02:36:14","guid":{"rendered":"http:\/\/myprojects.advchaweb.com\/?p=3538"},"modified":"2019-07-22T04:12:51","modified_gmt":"2019-07-22T04:12:51","slug":"install-and-configure-varnish-for-nginx-and-magento-2-on-ubuntu-16-04","status":"publish","type":"post","link":"https:\/\/myprojects.advchaweb.com\/index.php\/2019\/02\/08\/install-and-configure-varnish-for-nginx-and-magento-2-on-ubuntu-16-04\/","title":{"rendered":"Install and Configure Varnish for Nginx and Magento 2 on Ubuntu 16.04"},"content":{"rendered":"<p>Ref:<a href=\"https:\/\/blog.pusher.com\/speeding-up-your-website-using-varnish\/\">https:\/\/blog.pusher.com\/speeding-up-your-website-using-varnish\/<\/a><br \/>\n<a href=\"https:\/\/www.cyberciti.biz\/faq\/how-to-install-and-configure-varnish-cache-on-ubuntu-linux-16-04-lts\/\">https:\/\/www.cyberciti.biz\/faq\/how-to-install-and-configure-varnish-cache-on-ubuntu-linux-16-04-lts\/<\/a><br \/>\n<a href=\"https:\/\/www.howtoforge.com\/tutorial\/ubuntu-nginx-varnish\/\">https:\/\/www.howtoforge.com\/tutorial\/ubuntu-nginx-varnish\/<\/a><br \/>\n<a href=\"https:\/\/amasty.com\/blog\/use-varnish-with-magento-2-for-better-end-user-experience\/\">https:\/\/amasty.com\/blog\/use-varnish-with-magento-2-for-better-end-user-experience\/<\/a><\/p>\n<p>Install Varnish:<\/p>\n<pre class=\"lang:default decode:true \">teddy@teddy:~$ sudo apt-get update<\/pre>\n<pre class=\"lang:default decode:true \">teddy@teddy:~$ sudo apt-get install varnish\r\nReading package lists... Done\r\nBuilding dependency tree       \r\nReading state information... Done\r\nThe following packages were automatically installed and are no longer required:\r\n  libtidy5 libzip4 linux-headers-4.15.0-29 linux-headers-4.15.0-29-generic\r\n  linux-headers-4.15.0-30 linux-headers-4.15.0-30-generic\r\n  linux-headers-4.15.0-32 linux-headers-4.15.0-32-generic\r\n  linux-headers-4.15.0-33 linux-headers-4.15.0-33-generic\r\n  linux-headers-4.15.0-34 linux-headers-4.15.0-34-generic\r\n  linux-image-4.15.0-29-generic linux-image-4.15.0-30-generic\r\n  linux-image-4.15.0-32-generic linux-image-4.15.0-33-generic\r\n  linux-image-4.15.0-34-generic linux-modules-4.15.0-29-generic\r\n  linux-modules-4.15.0-30-generic linux-modules-4.15.0-32-generic\r\n  linux-modules-4.15.0-33-generic linux-modules-4.15.0-34-generic\r\n  linux-modules-extra-4.15.0-29-generic linux-modules-extra-4.15.0-30-generic\r\n  linux-modules-extra-4.15.0-32-generic linux-modules-extra-4.15.0-33-generic\r\n  linux-modules-extra-4.15.0-34-generic qtdeclarative5-controls-plugin\r\n  qtdeclarative5-dialogs-plugin\r\nUse 'sudo apt autoremove' to remove them.\r\nThe following additional packages will be installed:\r\n  libjemalloc1 libvarnishapi1\r\nSuggested packages:\r\n  varnish-doc\r\nThe following NEW packages will be installed:\r\n  libjemalloc1 libvarnishapi1 varnish\r\n0 upgraded, 3 newly installed, 0 to remove and 6 not upgraded.\r\nNeed to get 660 kB of archives.\r\nAfter this operation, 2.101 kB of additional disk space will be used.\r\nDo you want to continue? [Y\/n] Y\r\nGet:1 http:\/\/kambing.ui.ac.id\/ubuntu xenial-updates\/universe amd64 libvarnishapi1 amd64 4.1.1-1ubuntu0.2 [57,0 kB]\r\nGet:2 http:\/\/kambing.ui.ac.id\/ubuntu xenial\/universe amd64 libjemalloc1 amd64 3.6.0-9ubuntu1 [78,9 kB]\r\nGet:3 http:\/\/kambing.ui.ac.id\/ubuntu xenial-updates\/universe amd64 varnish amd64 4.1.1-1ubuntu0.2 [524 kB]\r\nFetched 660 kB in 1s (634 kB\/s)  \r\nSelecting previously unselected package libvarnishapi1.\r\n(Reading database ... 546972 files and directories currently installed.)\r\nPreparing to unpack ...\/libvarnishapi1_4.1.1-1ubuntu0.2_amd64.deb ...\r\nUnpacking libvarnishapi1 (4.1.1-1ubuntu0.2) ...\r\nSelecting previously unselected package libjemalloc1.\r\nPreparing to unpack ...\/libjemalloc1_3.6.0-9ubuntu1_amd64.deb ...\r\nUnpacking libjemalloc1 (3.6.0-9ubuntu1) ...\r\nSelecting previously unselected package varnish.\r\nPreparing to unpack ...\/varnish_4.1.1-1ubuntu0.2_amd64.deb ...\r\nUnpacking varnish (4.1.1-1ubuntu0.2) ...\r\nProcessing triggers for libc-bin (2.23-0ubuntu10) ...\r\nProcessing triggers for systemd (229-4ubuntu21.5) ...\r\nProcessing triggers for ureadahead (0.100.0-19) ...\r\nureadahead will be reprofiled on next reboot\r\nProcessing triggers for man-db (2.7.5-1) ...\r\nSetting up libvarnishapi1 (4.1.1-1ubuntu0.2) ...\r\nSetting up libjemalloc1 (3.6.0-9ubuntu1) ...\r\nSetting up varnish (4.1.1-1ubuntu0.2) ...\r\nProcessing triggers for libc-bin (2.23-0ubuntu10) ...\r\nProcessing triggers for systemd (229-4ubuntu21.5) ...\r\nProcessing triggers for ureadahead (0.100.0-19) ...<\/pre>\n<p>Start\/stop\/restart the varnish service:<\/p>\n<pre class=\"lang:default decode:true\">teddy@teddy:~$ sudo service varnish start\r\nteddy@teddy:~$ sudo service varnish stop\r\nteddy@teddy:~$ sudo service varnish restart\r\n<\/pre>\n<p>Check the varnish status (when active):<\/p>\n<pre class=\"lang:default decode:true\">teddy@teddy:~$ sudo service varnish status\r\n\u25cf varnish.service - Varnish HTTP accelerator\r\n   Loaded: loaded (\/lib\/systemd\/system\/varnish.service; enabled; vendor preset: \r\n   Active: active (running) since Jum 2019-02-08 09:39:10 WIB; 2min 27s ago\r\n     Docs: https:\/\/www.varnish-cache.org\/docs\/4.1\/\r\n           man:varnishd\r\n Main PID: 15892 (varnishd)\r\n   CGroup: \/system.slice\/varnish.service\r\n           \u251c\u250015892 \/usr\/sbin\/varnishd -j unix,user=vcache -F -a :6081 -T localho\r\n           \u2514\u250015959 \/usr\/sbin\/varnishd -j unix,user=vcache -F -a :6081 -T localho\r\n\r\nPeb 08 09:39:10 teddy systemd[1]: Started Varnish HTTP accelerator.\r\nPeb 08 09:39:10 teddy varnishd[15892]: Debug: Platform: Linux,4.15.0-38-generic,\r\nPeb 08 09:39:10 teddy varnishd[15892]: Platform: Linux,4.15.0-38-generic,x86_64,\r\nPeb 08 09:39:10 teddy varnishd[15892]: Debug: Child (15959) Started\r\nPeb 08 09:39:10 teddy varnishd[15892]: Child (15959) Started\r\nPeb 08 09:39:10 teddy varnishd[15892]: Info: Child (15959) said Child starts\r\nPeb 08 09:39:10 teddy varnishd[15892]: Child (15959) said Child starts\r\nPeb 08 09:40:55 teddy systemd[1]: Started Varnish HTTP accelerator.<\/pre>\n<p>Varnish installed and it is a default configured to listen on port 6081 and 6082 for varnish admin:<\/p>\n<pre class=\"lang:default decode:true \">teddy@teddy:~$ netstat -tulpn\r\n(Not all processes could be identified, non-owned process info\r\n will not be shown, you would have to be root to see it all.)\r\nActive Internet connections (only servers)\r\nProto Recv-Q Send-Q Local Address           Foreign Address         State       PID\/Program name\r\n...               \r\ntcp        0      0 0.0.0.0:6081            0.0.0.0:*               LISTEN      -               \r\ntcp        0      0 127.0.0.1:6082          0.0.0.0:*               LISTEN\r\n...<\/pre>\n<p>When we open on the browser: http:\/\/localhost:6081\/, we&#8217;d get a varnish error page<a href=\"http:\/\/myprojects.advchaweb.com\/wp-content\/uploads\/2019\/02\/varnish_error.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3544\" src=\"http:\/\/myprojects.advchaweb.com\/wp-content\/uploads\/2019\/02\/varnish_error.jpg\" alt=\"\" width=\"540\" height=\"271\" srcset=\"https:\/\/myprojects.advchaweb.com\/wp-content\/uploads\/2019\/02\/varnish_error.jpg 540w, https:\/\/myprojects.advchaweb.com\/wp-content\/uploads\/2019\/02\/varnish_error-300x151.jpg 300w\" sizes=\"auto, (max-width: 540px) 85vw, 540px\" \/><\/a>However http:\/\/localhost:6082\/ will show page error.<br \/>\nWe will be changing this so it listens on port 80 (fontaineind use the default port 6081 for varnish)\u00a0 and Nginx listens on port 8080. To do this, edit your site\u2019s Nginx configuration file. In our case, this file is\u00a0\/etc\/nginx\/sites-available\/fontaineind.test.<\/p>\n<pre class=\"lang:default decode:true \">teddy@teddy:~$ sudo gedit \/etc\/nginx\/sites-available\/fontaineind.test<\/pre>\n<p>modify<\/p>\n<pre class=\"lang:default decode:true \">listen 80;\r\nto\r\nlisten 8080;<\/pre>\n<p>Save the file. Then restart nginx server:<\/p>\n<pre class=\"lang:default decode:true \">sudo service nginx restart<\/pre>\n<p>When you open your website with the port 8080, http:\/\/fontaineind.test:8080, It&#8217;d show the website but the css seems missing! I think I need to clear the cache and rebuild the cache. but it show an expected error.<\/p>\n<pre class=\"lang:default decode:true \">teddy@teddy:~\/Documents\/works\/fontaineind$ sudo su -s \/bin\/bash www-data\r\nwww-data@teddy:\/home\/teddy\/Documents\/works\/fontaineind$ php bin\/magento c:f\r\n\r\n\r\n                                                       \r\n  [InvalidArgumentException]                           \r\n  There are no commands defined in the \"c\" namespace.<\/pre>\n<p>Another error when trying to show the magento 2 command:<\/p>\n<pre class=\"lang:default decode:true \">www-data@teddy:\/home\/teddy\/Documents\/works\/fontaineind$ php bin\/magento \r\nMagento CLI version 2.1.9\r\n\r\nUsage:\r\n command [options] [arguments]\r\n\r\nOptions:\r\n --help (-h)           Display this help message\r\n...\r\n\r\nAvailable commands:\r\n help   Displays help for a command\r\n list   Lists commands\r\nWe're sorry, an error occurred. Try clearing the cache and code generation directories. By default, they are: var\/cache, var\/di, var\/generation, and var\/page_cache.\r\n\r\n\r\n                                                                               \r\n  [Exception]                                                                  \r\n  Deprecated Functionality: The each() function is deprecated. This message w  \r\n  ill be suppressed on further calls in \/home\/teddy\/Documents\/works\/fontainei  \r\n  nd\/vendor\/colinmollenhour\/cache-backend-file\/File.php on line 81<\/pre>\n<p>Solution: THIS IS BECAUSE I USE PHP 7.2. CHANGE IT TO PHP 7.0<\/p>\n<pre class=\"lang:default decode:true \">teddy@teddy:~\/Documents\/works\/fontaineind$ sudo ln -sfn \/usr\/bin\/php7.0 \/etc\/alternatives\/php \r\nteddy@teddy:~\/Documents\/works\/fontaineind$ php -v\r\nPHP 7.0.33-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Dec  7 2018 08:27:52) ( NTS )\r\nCopyright (c) 1997-2017 The PHP Group\r\nZend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies\r\n    with Zend OPcache v7.0.33-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2017, by Zend Technologies\r\n    with Xdebug v2.6.1, Copyright (c) 2002-2018, by Derick Rethans<\/pre>\n<p>Then the magento 2 command is running well back.<\/p>\n<p>also probably I need to change the base url to include the port 8080? &#8211;&gt; NO NEED. we will take it later. Let&#8217;s continue.<\/p>\n<p>Now that port 80 is free (NO. I NEED TO CHECK IT VIA sudo netstat -plntu | grep &#8216;:80&#8217;), let\u2019s configure Varnish to be the one that responds. Open the file\u00a0\/etc\/default\/varnish\u00a0for editing. Here is the default content.<\/p>\n<pre class=\"lang:default decode:true\"># Configuration file for varnish\r\n#\r\n# \/etc\/init.d\/varnish expects the variables $DAEMON_OPTS, $NFILES and $MEMLOCK\r\n# to be set from this shell script fragment.\r\n#\r\n# Note: If systemd is installed, this file is obsolete and ignored.  Please see \r\n# \/usr\/share\/doc\/varnish\/examples\/varnish.systemd-drop-in.conf\r\n\r\n# Should we start varnishd at boot?  Set to \"no\" to disable.\r\nSTART=yes\r\n\r\n# Maximum number of open files (for ulimit -n)\r\nNFILES=131072\r\n\r\n# Maximum locked memory size (for ulimit -l)\r\n# Used for locking the shared memory log in memory.  If you increase log size,\r\n# you need to increase this number as well\r\nMEMLOCK=82000\r\n\r\n# Default varnish instance name is the local nodename.  Can be overridden with\r\n# the -n switch, to have more instances on a single server.\r\n# You may need to uncomment this variable for alternatives 1 and 3 below.\r\n# INSTANCE=$(uname -n)\r\n\r\n# This file contains 4 alternatives, please use only one.\r\n\r\n## Alternative 1, Minimal configuration, no VCL\r\n#\r\n# Listen on port 6081, administration on localhost:6082, and forward to\r\n# content server on localhost:8080.  Use a 1GB fixed-size cache file.\r\n#\r\n# This example uses the INSTANCE variable above, which you need to uncomment.\r\n#\r\n# DAEMON_OPTS=\"-a :6081 \\\r\n#              -T localhost:6082 \\\r\n# \t     -b localhost:8080 \\\r\n# \t     -u varnish -g varnish \\\r\n#            -S \/etc\/varnish\/secret \\\r\n# \t     -s file,\/var\/lib\/varnish\/$INSTANCE\/varnish_storage.bin,1G\"\r\n\r\n\r\n## Alternative 2, Configuration with VCL\r\n#\r\n# Listen on port 6081, administration on localhost:6082, and forward to\r\n# one content server selected by the vcl file, based on the request.\r\n#\r\nDAEMON_OPTS=\"-a :6081 \\\r\n             -T localhost:6082 \\\r\n             -f \/etc\/varnish\/default.vcl \\\r\n             -S \/etc\/varnish\/secret \\\r\n             -s malloc,256m\"\r\n\r\n\r\n## Alternative 3, Advanced configuration\r\n#\r\n# This example uses the INSTANCE variable above, which you need to uncomment.\r\n#\r\n# See varnishd(1) for more information.\r\n#\r\n# # Main configuration file. You probably want to change it :)\r\n# VARNISH_VCL_CONF=\/etc\/varnish\/default.vcl\r\n#\r\n# # Default address and port to bind to\r\n# # Blank address means all IPv4 and IPv6 interfaces, otherwise specify\r\n# # a host name, an IPv4 dotted quad, or an IPv6 address in brackets.\r\n# VARNISH_LISTEN_ADDRESS=\r\n# VARNISH_LISTEN_PORT=6081\r\n#\r\n# # Telnet admin interface listen address and port\r\n# VARNISH_ADMIN_LISTEN_ADDRESS=127.0.0.1\r\n# VARNISH_ADMIN_LISTEN_PORT=6082\r\n#\r\n# # Cache file location\r\n# VARNISH_STORAGE_FILE=\/var\/lib\/varnish\/$INSTANCE\/varnish_storage.bin\r\n#\r\n# # Cache file size: in bytes, optionally using k \/ M \/ G \/ T suffix,\r\n# # or in percentage of available disk space using the % suffix.\r\n# VARNISH_STORAGE_SIZE=1G\r\n#\r\n# # File containing administration secret\r\n# VARNISH_SECRET_FILE=\/etc\/varnish\/secret\r\n# \r\n# # Backend storage specification\r\n# VARNISH_STORAGE=\"file,${VARNISH_STORAGE_FILE},${VARNISH_STORAGE_SIZE}\"\r\n#\r\n# # Default TTL used when the backend does not specify one\r\n# VARNISH_TTL=120\r\n#\r\n# # DAEMON_OPTS is used by the init script.  If you add or remove options, make\r\n# # sure you update this section, too.\r\n# DAEMON_OPTS=\"-a ${VARNISH_LISTEN_ADDRESS}:${VARNISH_LISTEN_PORT} \\\r\n#              -f ${VARNISH_VCL_CONF} \\\r\n#              -T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT} \\\r\n#              -t ${VARNISH_TTL} \\\r\n# \t       -S ${VARNISH_SECRET_FILE} \\\r\n#              -s ${VARNISH_STORAGE}\"\r\n#\r\n\r\n\r\n## Alternative 4, Do It Yourself\r\n#\r\n# DAEMON_OPTS=\"\"<\/pre>\n<p>Look for the line below:<\/p>\n<pre class=\"lang:default decode:true\">DAEMON_OPTS=\"-a :6081 \\\r\n             -T localhost:6082 \\\r\n             -f \/etc\/varnish\/default.vcl \\\r\n             -S \/etc\/varnish\/secret \\\r\n             -s malloc,256m\"<\/pre>\n<p>change &#8216;-a :6081&#8217; to &#8216;-a :80&#8217;:<\/p>\n<pre class=\"lang:default decode:true\">DAEMON_OPTS=\"-a :80 \\\r\n             -T localhost:6082 \\\r\n             -f \/etc\/varnish\/default.vcl \\\r\n             -S \/etc\/varnish\/secret \\\r\n             -s malloc,256m\"<\/pre>\n<p>Save the file.<br \/>\nNOTE: I also can change the malloc. malloc is RAM usage for Varnish. Default is 256m. I can change it to (for example) 1024m (1G)<\/p>\n<p>Next, open the file\u00a0\/etc\/varnish\/default.vcl\u00a0and check that the default backend is set to port\u00a08080, because this is where Nginx serves from now. Look for the line below and make sure the\u00a0.port\u00a0is\u00a08080. Here is the default content:<\/p>\n<pre class=\"lang:default decode:true\">#\r\n# This is an example VCL file for Varnish.\r\n#\r\n# It does not do anything by default, delegating control to the\r\n# builtin VCL. The builtin VCL is called when there is no explicit\r\n# return statement.\r\n#\r\n# See the VCL chapters in the Users Guide at https:\/\/www.varnish-cache.org\/docs\/\r\n# and https:\/\/www.varnish-cache.org\/trac\/wiki\/VCLExamples for more examples.\r\n\r\n# Marker to tell the VCL compiler that this VCL has been adapted to the\r\n# new 4.0 format.\r\nvcl 4.0;\r\n\r\n# Default backend definition. Set this to point to your content server.\r\nbackend default {\r\n    .host = \"127.0.0.1\";\r\n    .port = \"8080\";\r\n}\r\n\r\nsub vcl_recv {\r\n    # Happens before we check if we have this in cache already.\r\n    #\r\n    # Typically you clean up the request here, removing cookies you don't need,\r\n    # rewriting the request, etc.\r\n}\r\n\r\nsub vcl_backend_response {\r\n    # Happens after we have read the response headers from the backend.\r\n    #\r\n    # Here you clean the response headers, removing silly Set-Cookie headers\r\n    # and other mistakes your backend does.\r\n}\r\n\r\nsub vcl_deliver {\r\n    # Happens when we have all the pieces we need, and are about to send the\r\n    # response to the client.\r\n    #\r\n    # You can do accounting or modifying the final object here.\r\n}<\/pre>\n<p>NOTE: For the explanation of vcl_recv, vcl_backend_response and vcl_deliver, pls read <a href=\"https:\/\/amasty.com\/blog\/use-varnish-with-magento-2-for-better-end-user-experience\/\">https:\/\/amasty.com\/blog\/use-varnish-with-magento-2-for-better-end-user-experience\/<\/a><br \/>\nmake sure the backend port is 8080<\/p>\n<pre class=\"lang:default decode:true \">...\r\nbackend default {\r\n    .host = \"127.0.0.1\";\r\n    .port = \"8080\";\r\n...<\/pre>\n<p>Once you have confirmed this, the next thing will be to copy the\u00a0varnish.service\u00a0file to our systemd directory. This will enable systemd to start varnish on port 80. Run the command below:<\/p>\n<pre class=\"lang:default decode:true \">teddy@teddy:~\/Documents\/works\/fontaineind$ sudo cp \/lib\/systemd\/system\/varnish.service \/etc\/systemd\/system\/\r\nteddy@teddy:~\/Documents\/works\/fontaineind$ sudo gedit \/etc\/systemd\/system\/varnish.service<\/pre>\n<p>This will copy the varnish service file, and then open an editor with the contents.<\/p>\n<pre class=\"lang:default decode:true \">[Unit]\r\nDescription=Varnish HTTP accelerator\r\nDocumentation=https:\/\/www.varnish-cache.org\/docs\/4.1\/ man:varnishd\r\n\r\n[Service]\r\nType=simple\r\nLimitNOFILE=131072\r\nLimitMEMLOCK=82000\r\nExecStart=\/usr\/sbin\/varnishd -j unix,user=vcache -F -a :6081 -T localhost:6082 -f \/etc\/varnish\/default.vcl -S \/etc\/varnish\/secret -s malloc,256m\r\nExecReload=\/usr\/share\/varnish\/reload-vcl\r\nProtectSystem=full\r\nProtectHome=true\r\nPrivateTmp=true\r\nPrivateDevices=true\r\n\r\n[Install]\r\nWantedBy=multi-user.target<\/pre>\n<p>Look for the\u00a0ExecStart\u00a0line:<\/p>\n<pre class=\"lang:default decode:true \">ExecStart=\/usr\/sbin\/varnishd -j unix,user=vcache -F -a :6081 -T localhost:6082 -f \/etc\/varnish\/default.vcl -S \/etc\/varnish\/secret -s malloc,256m<\/pre>\n<p>Now change the\u00a0-F -a :6081\u00a0to\u00a0-F -a :80. Leave the\u00a0localhost:6082\u00a0on the same line as it is. Now save and exit the file. Run the commands below to reload everything you have just configured:<\/p>\n<pre class=\"lang:default decode:true \">teddy@teddy:~\/Documents\/works\/fontaineind$ sudo systemctl daemon-reload\r\nteddy@teddy:~\/Documents\/works\/fontaineind$ sudo systemctl reload varnish.serviceteddy@teddy:~\/Documents\/works\/fontaineind$ sudo service varnish restart\r\nteddy@teddy:~\/Documents\/works\/fontaineind$ sudo service nginx restart<\/pre>\n<p>The commands above will reload the system daemon, reload varnish, restart the varnish service, and restart Nginx.<br \/>\nNOTE: I need to check the varnish status as well. Varnish can&#8217;t start because port 80 already is use:<\/p>\n<pre class=\"lang:default decode:true\">teddy@teddy:~\/Documents\/works\/fontaineind$ sudo service varnish start\r\nteddy@teddy:~\/Documents\/works\/fontaineind$ sudo service varnish status\r\nvarnish.service - Varnish HTTP accelerator\r\n   Loaded: loaded (\/etc\/systemd\/system\/varnish.service; enabled; vendor preset: enabled)\r\n   Active: failed (Result: exit-code) since Jum 2019-02-08 10:47:44 WIB; 1s ago\r\n     Docs: https:\/\/www.varnish-cache.org\/docs\/4.1\/\r\n           man:varnishd\r\n  Process: 19051 ExecReload=\/usr\/share\/varnish\/reload-vcl (code=exited, status=0\/SUCCESS)\r\n  Process: 20664 ExecStart=\/usr\/sbin\/varnishd -j unix,user=vcache -F -a :80 -T localhost:6082 -f \/\r\n Main PID: 20664 (code=exited, status=2)\r\n\r\nPeb 08 10:47:44 teddy systemd[1]: Started Varnish HTTP accelerator.\r\nPeb 08 10:47:44 teddy varnishd[20664]: Error: Cannot open socket: :80: Address already in use   &lt;---------------------\r\nPeb 08 10:47:44 teddy systemd[1]: varnish.service: Main process exited, code=exited, status=2\/INVA\r\nPeb 08 10:47:44 teddy systemd[1]: varnish.service: Unit entered failed state.\r\nPeb 08 10:47:44 teddy systemd[1]: varnish.service: Failed with result 'exit-code'.<\/pre>\n<p>Check who is using port 80:<\/p>\n<pre class=\"lang:default decode:true\">teddy@teddy:\/var\/log$ sudo netstat -plntu | grep ':80'\r\ntcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      19110\/nginx -g daem\r\ntcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      19110\/nginx -g daem\r\ntcp6       0      0 :::80                   :::*                    LISTEN      19110\/nginx -g daem<\/pre>\n<p>it seems nginx with pid 19110 is using both port 80 and 8080. or here is the complete list:<\/p>\n<pre class=\"lang:default decode:true\">teddy@teddy:\/var\/log$ sudo lsof -i ':80'\r\nCOMMAND   PID     USER   FD   TYPE DEVICE SIZE\/OFF NODE NAME\r\nfirefox  5044    teddy  159u  IPv4 163157      0t0  TCP 192.168.1.3:47334-&gt;us3.clientdomainmanager.org:http (ESTABLISHED)\r\nnginx   19110     root    8u  IPv4 146484      0t0  TCP *:http (LISTEN)\r\nnginx   19110     root    9u  IPv6 146485      0t0  TCP *:http (LISTEN)\r\nnginx   19111 www-data    8u  IPv4 146484      0t0  TCP *:http (LISTEN)\r\nnginx   19111 www-data    9u  IPv6 146485      0t0  TCP *:http (LISTEN)\r\nnginx   19112 www-data    8u  IPv4 146484      0t0  TCP *:http (LISTEN)\r\nnginx   19112 www-data    9u  IPv6 146485      0t0  TCP *:http (LISTEN)\r\nnginx   19113 www-data    8u  IPv4 146484      0t0  TCP *:http (LISTEN)\r\nnginx   19113 www-data    9u  IPv6 146485      0t0  TCP *:http (LISTEN)\r\nnginx   19114 www-data    8u  IPv4 146484      0t0  TCP *:http (LISTEN)\r\nnginx   19114 www-data    9u  IPv6 146485      0t0  TCP *:http (LISTEN)\r\nnginx   19115 www-data    8u  IPv4 146484      0t0  TCP *:http (LISTEN)\r\nnginx   19115 www-data    9u  IPv6 146485      0t0  TCP *:http (LISTEN)\r\nnginx   19116 www-data    8u  IPv4 146484      0t0  TCP *:http (LISTEN)\r\nnginx   19116 www-data    9u  IPv6 146485      0t0  TCP *:http (LISTEN)\r\nnginx   19117 www-data    8u  IPv4 146484      0t0  TCP *:http (LISTEN)\r\nnginx   19117 www-data    9u  IPv6 146485      0t0  TCP *:http (LISTEN)\r\nnginx   19118 www-data    8u  IPv4 146484      0t0  TCP *:http (LISTEN)\r\nnginx   19118 www-data    9u  IPv6 146485      0t0  TCP *:http (LISTEN)<\/pre>\n<p>Solution: nginx use both ports 80 and 8080 because in sites-enabled directory there are many nginx setting for different websites that it still use port 80.<\/p>\n<pre class=\"lang:default decode:true \">teddy@teddy:\/etc\/nginx\/sites-enabled$ ls\r\naliceisback.test   ko32example.test      notarisfemira.test  silverstripe.test\r\ncraftcms.test      kohana.test           orangescrum.test    stickercollective.test\r\ndefault            kokopage.test         osclass374.test     tff-magento2.test\r\nengelcoolers.test  koseven.test          persuratan.test     wordpress498.test\r\nfontaineind.test   laravel-voyager.test  pethome.test        yclass.test\r\nhitchnpitch2.test  magento19.test        phpmyadmin.test\r\nhitchnpitch.test   magento222.test       resales.test\r\nkirby.test         magentoce215.test     sc2.test<\/pre>\n<p>SO. REPLACE THE PORT 80 TO 8080 FOR ALL WEBSITE IN SITES-ENABLES DIRECTORY!!!<br \/>\nAFTER I CHANGED THE PORT IN ALL THE WEBSITE, NO MORE APPLICATION USE PORT 80 ANYMORE<\/p>\n<pre class=\"lang:default decode:true \">teddy@teddy:\/etc\/nginx\/sites-enabled$ sudo netstat -plntu | grep ':80'\r\ntcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      30008\/nginx -g daem\r\ntcp6       0      0 :::8080                 :::*                    LISTEN      30008\/nginx -g daem\r\n<\/pre>\n<p>OR<\/p>\n<pre class=\"lang:default decode:true \">teddy@teddy:\/etc\/nginx\/sites-enabled$ sudo netstat -plntu | grep nginx\r\ntcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      30008\/nginx -g daem\r\ntcp6       0      0 :::8080                 :::*                    LISTEN      30008\/nginx -g daem\r\n<\/pre>\n<p>Nginx is using port 8080 now. I can start varnish and check the status:<\/p>\n<pre class=\"lang:default decode:true \">teddy@teddy:\/etc\/nginx\/sites-enabled$ sudo service varnish start\r\nteddy@teddy:\/etc\/nginx\/sites-enabled$ sudo service varnish status\r\n\u25cf varnish.service - Varnish HTTP accelerator\r\n   Loaded: loaded (\/etc\/systemd\/system\/varnish.service; enabled; vendor preset: enabled)\r\n   Active: active (running) since Jum 2019-02-08 14:02:22 WIB; 4s ago\r\n     Docs: https:\/\/www.varnish-cache.org\/docs\/4.1\/\r\n           man:varnishd\r\n  Process: 19051 ExecReload=\/usr\/share\/varnish\/reload-vcl (code=exited, status=0\/SUCCESS)\r\n Main PID: 30257 (varnishd)\r\n   CGroup: \/system.slice\/varnish.service\r\n           \u251c\u250030257 \/usr\/sbin\/varnishd -j unix,user=vcache -F -a :80 -T localhost:6082 -f \/etc\/varn\r\n           \u2514\u250030267 \/usr\/sbin\/varnishd -j unix,user=vcache -F -a :80 -T localhost:6082 -f \/etc\/varn\r\n\r\nPeb 08 14:02:22 teddy systemd[1]: Started Varnish HTTP accelerator.\r\nPeb 08 14:02:23 teddy varnishd[30257]: Debug: Platform: Linux,4.15.0-38-generic,x86_64,-junix,-sma\r\nPeb 08 14:02:23 teddy varnishd[30257]: Platform: Linux,4.15.0-38-generic,x86_64,-junix,-smalloc,-s\r\nPeb 08 14:02:23 teddy varnishd[30257]: Debug: Child (30267) Started\r\nPeb 08 14:02:23 teddy varnishd[30257]: Child (30267) Started\r\nPeb 08 14:02:23 teddy varnishd[30257]: Info: Child (30267) said Child starts\r\nPeb 08 14:02:23 teddy varnishd[30257]: Child (30267) said Child starts<\/pre>\n<p>NOTE: TO RUN THE OTHERS RUNNING WEBSITE (WITHOUT VARNISH RUINNING) THAT IT HAD BEEN WORKING PREVIOUSLY, I NEED TO ADD THE PORT 8080 AT THE END OF THE URL. FOR EXAMPLE:<br \/>\nhttp:\/\/localhost:8080\/phpinfo.php<br \/>\nhttp:\/\/notarisfemira.test:8080\/<br \/>\nhttp:\/\/phpmyadmin.test:8080<\/p>\n<p>Now visit the IP of your web page and you should see nothing has changed. However, when you run it through the HTTP checker we used before, you should see that the headers have changed.<br \/>\nhttp:\/\/fontaineind.test\/ &#8211;&gt; First time run about 20 seconds<\/p>\n<pre class=\"lang:default decode:true \">Request URL: http:\/\/fontaineind.test\/\r\nRequest Method: GET\r\nStatus Code: 200 OK\r\nRemote Address: 127.0.0.1:80\r\nReferrer Policy: no-referrer-when-downgrade\r\nAccept-Ranges: bytes\r\nAge: 0\r\nCache-Control: max-age=0, must-revalidate, no-cache, no-store\r\nConnection: keep-alive\r\nContent-Encoding: gzip\r\nContent-Type: text\/html; charset=UTF-8\r\nDate: Fri, 08 Feb 2019 07:06:16 GMT\r\nExpires: Thu, 08 Feb 2018 07:06:16 GMT\r\nPragma: no-cache\r\nServer: nginx\/1.10.3 (Ubuntu)\r\nSet-Cookie: X-Magento-Vary=1824d10cc0bdb1434527d6e3f2eb93ec93279e70; path=\/; HttpOnly\r\nTransfer-Encoding: chunked\r\nVary: Accept-Encoding\r\nVia: 1.1 varnish-v4\r\nX-Content-Type-Options: nosniff\r\nX-Frame-Options: SAMEORIGIN\r\nX-Varnish: 11\r\nX-XSS-Protection: 1; mode=block\r\nAccept: text\/html,application\/xhtml+xml,application\/xml;q=0.9,image\/webp,image\/apng,*\/*;q=0.8\r\nAccept-Encoding: gzip, deflate\r\nAccept-Language: en-US,en;q=0.9\r\nCache-Control: no-cache\r\nConnection: keep-alive\r\nCookie: _ga=GA1.2.153436117.1539751926; __zlcmid=ovhiooeabcbDF8; fastest-popup=true; __atuvc=1%7C48%2C1%7C49; persistent_shopping_cart=1KnMotS8bUecwuFfLz4ZWnjaHxkFBegbdLoTMPtSV1vnmhuz8m; PHPSESSID=a81ae6cda46l21cvknvu7prsb3; form_key=tcwxhKGXlLxlM34K; _gid=GA1.2.1663350196.1549590795; mage-translation-storage=%7B%7D; mage-translation-file-version=%7B%7D; mage-cache-storage=%7B%7D; mage-cache-storage-section-invalidation=%7B%7D; _hjIncludedInSample=1; mage-cache-sessid=true; X-Magento-Vary=1824d10cc0bdb1434527d6e3f2eb93ec93279e70; mage-messages=; private_content_version=f2172c778c79ea181e3586015b2ef162; section_data_ids=%7B%22cart%22%3A1549592685%2C%22wishlist%22%3A1549592684%2C%22last-ordered-items%22%3A1549592684%2C%22customer%22%3A1549590799%2C%22compare-products%22%3A1549590799%2C%22directory-data%22%3A1549590799%2C%22review%22%3A1549590799%2C%22crosssell_products%22%3A1549590799%2C%22paypal-billing-agreement%22%3A1549590799%7D\r\nHost: fontaineind.test\r\nPragma: no-cache\r\nUpgrade-Insecure-Requests: 1\r\nUser-Agent: Mozilla\/5.0 (X11; Linux x86_64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/72.0.3626.81 Safari\/537.36<\/pre>\n<p>The second run (refresh) about 9 seconds<\/p>\n<pre class=\"lang:default decode:true \">Request URL: http:\/\/fontaineind.test\/\r\nRequest Method: GET\r\nStatus Code: 200 OK\r\nRemote Address: 127.0.0.1:80\r\nReferrer Policy: no-referrer-when-downgrade\r\nAccept-Ranges: bytes\r\nAge: 0\r\nCache-Control: max-age=0, must-revalidate, no-cache, no-store\r\nConnection: keep-alive\r\nContent-Encoding: gzip\r\nContent-Type: text\/html; charset=UTF-8\r\nDate: Fri, 08 Feb 2019 07:09:41 GMT\r\nExpires: Thu, 08 Feb 2018 07:06:16 GMT\r\nPragma: no-cache\r\nServer: nginx\/1.10.3 (Ubuntu)\r\nSet-Cookie: X-Magento-Vary=1824d10cc0bdb1434527d6e3f2eb93ec93279e70; path=\/; HttpOnly\r\nTransfer-Encoding: chunked\r\nVary: Accept-Encoding\r\nVia: 1.1 varnish-v4\r\nX-Cache-Warmer: HIT\r\nX-Content-Type-Options: nosniff\r\nX-Frame-Options: SAMEORIGIN\r\nX-Varnish: 32841\r\nX-XSS-Protection: 1; mode=block\r\nAccept: text\/html,application\/xhtml+xml,application\/xml;q=0.9,image\/webp,image\/apng,*\/*;q=0.8\r\nAccept-Encoding: gzip, deflate\r\nAccept-Language: en-US,en;q=0.9\r\nCache-Control: no-cache\r\nConnection: keep-alive\r\nCookie: _ga=GA1.2.153436117.1539751926; __zlcmid=ovhiooeabcbDF8; fastest-popup=true; __atuvc=1%7C48%2C1%7C49; persistent_shopping_cart=1KnMotS8bUecwuFfLz4ZWnjaHxkFBegbdLoTMPtSV1vnmhuz8m; PHPSESSID=a81ae6cda46l21cvknvu7prsb3; form_key=tcwxhKGXlLxlM34K; _gid=GA1.2.1663350196.1549590795; mage-translation-storage=%7B%7D; mage-translation-file-version=%7B%7D; mage-cache-storage=%7B%7D; mage-cache-storage-section-invalidation=%7B%7D; _hjIncludedInSample=1; mage-cache-sessid=true; X-Magento-Vary=1824d10cc0bdb1434527d6e3f2eb93ec93279e70; mage-messages=; private_content_version=ec5f01fcb88dd0469d065a446f519922; section_data_ids=%7B%22cart%22%3A1549609584%2C%22wishlist%22%3A1549609582%2C%22last-ordered-items%22%3A1549609582%2C%22customer%22%3A1549609582%2C%22compare-products%22%3A1549609582%2C%22directory-data%22%3A1549609584%2C%22review%22%3A1549609582%2C%22crosssell_products%22%3A1549609582%2C%22paypal-billing-agreement%22%3A1549609582%7D\r\nHost: fontaineind.test\r\nPragma: no-cache\r\nUpgrade-Insecure-Requests: 1\r\nUser-Agent: Mozilla\/5.0 (X11; Linux x86_64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/72.0.3626.81 Safari\/537.36<\/pre>\n<p>NOTE: I can see some variables like X-Varnish and Age. But why Age still 0 on the refresh page? It means it miss the cache.<br \/>\nIn magento, I already enabled Page Cache and Block HTML cache.<\/p>\n<p>Configure Magento to use Varnish<br \/>\nTo configure Magento to use Varnish:<\/p>\n<p>Log in to the\u00a0Magento Admin\u00a0as an administrator.<br \/>\nClick\u00a0STORES\u00a0&gt;\u00a0Configuration\u00a0&gt;\u00a0ADVANCED\u00a0&gt;\u00a0System\u00a0&gt;\u00a0Full Page Cache.<br \/>\nFrom the\u00a0Caching Application\u00a0list, click\u00a0Varnish Cache (recommended).<br \/>\nEnter a value in the\u00a0TTL for public content\u00a0field.<br \/>\nExpand\u00a0Varnish Configuration\u00a0and enter the following information:<br \/>\nAccess list:\u00a0localhost \u00a0 &#8211;&gt; 172.31.31.224 for fontaineind.com.au<br \/>\nBackend host:\u00a0localhost \u00a0 &#8211;&gt; 172.31.31.224 for fontaineind.com.au<br \/>\nBackend port: 8080<br \/>\nThen click a button &#8216;Export VCL for Varnish 4&#8217; -&gt; It&#8217;d create a file &#8216;varnish.vcl&#8217; and download it.<br \/>\nHere is the file content:<\/p>\n<pre class=\"lang:default decode:true \">vcl 4.0;\r\n\r\nimport std;\r\n# The minimal Varnish version is 4.0\r\n# For SSL offloading, pass the following header in your proxy server or load balancer: 'X-Forwarded-Proto: https'\r\n\r\nbackend default {\r\n    .host = \"localhost\";\r\n    .port = \"8080\";\r\n}\r\n\r\nacl purge {\r\n    \"localhost\";\r\n}\r\n\r\nsub vcl_recv {\r\n    if (req.method == \"PURGE\") {\r\n        if (client.ip !~ purge) {\r\n            return (synth(405, \"Method not allowed\"));\r\n        }\r\n        if (!req.http.X-Magento-Tags-Pattern) {\r\n            return (synth(400, \"X-Magento-Tags-Pattern header required\"));\r\n        }\r\n        ban(\"obj.http.X-Magento-Tags ~ \" + req.http.X-Magento-Tags-Pattern);\r\n        return (synth(200, \"Purged\"));\r\n    }\r\n\r\n    if (req.method != \"GET\" &amp;&amp;\r\n        req.method != \"HEAD\" &amp;&amp;\r\n        req.method != \"PUT\" &amp;&amp;\r\n        req.method != \"POST\" &amp;&amp;\r\n        req.method != \"TRACE\" &amp;&amp;\r\n        req.method != \"OPTIONS\" &amp;&amp;\r\n        req.method != \"DELETE\") {\r\n          \/* Non-RFC2616 or CONNECT which is weird. *\/\r\n          return (pipe);\r\n    }\r\n\r\n    # We only deal with GET and HEAD by default\r\n    if (req.method != \"GET\" &amp;&amp; req.method != \"HEAD\") {\r\n        return (pass);\r\n    }\r\n\r\n    # Bypass shopping cart, checkout and search requests\r\n    if (req.url ~ \"\/checkout\" || req.url ~ \"\/catalogsearch\") {\r\n        return (pass);\r\n    }\r\n\r\n    # normalize url in case of leading HTTP scheme and domain\r\n    set req.url = regsub(req.url, \"^http[s]?:\/\/\", \"\");\r\n\r\n    # collect all cookies\r\n    std.collect(req.http.Cookie);\r\n\r\n    # Compression filter. See https:\/\/www.varnish-cache.org\/trac\/wiki\/FAQ\/Compression\r\n    if (req.http.Accept-Encoding) {\r\n        if (req.url ~ \"\\.(jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf|flv)$\") {\r\n            # No point in compressing these\r\n            unset req.http.Accept-Encoding;\r\n        } elsif (req.http.Accept-Encoding ~ \"gzip\") {\r\n            set req.http.Accept-Encoding = \"gzip\";\r\n        } elsif (req.http.Accept-Encoding ~ \"deflate\" &amp;&amp; req.http.user-agent !~ \"MSIE\") {\r\n            set req.http.Accept-Encoding = \"deflate\";\r\n        } else {\r\n            # unkown algorithm\r\n            unset req.http.Accept-Encoding;\r\n        }\r\n    }\r\n\r\n    # Remove Google gclid parameters to minimize the cache objects\r\n    set req.url = regsuball(req.url,\"\\?gclid=[^&amp;]+$\",\"\"); # strips when QS = \"?gclid=AAA\"\r\n    set req.url = regsuball(req.url,\"\\?gclid=[^&amp;]+&amp;\",\"?\"); # strips when QS = \"?gclid=AAA&amp;foo=bar\"\r\n    set req.url = regsuball(req.url,\"&amp;gclid=[^&amp;]+\",\"\"); # strips when QS = \"?foo=bar&amp;gclid=AAA\" or QS = \"?foo=bar&amp;gclid=AAA&amp;bar=baz\"\r\n\r\n    # static files are always cacheable. remove SSL flag and cookie\r\n        if (req.url ~ \"^\/(pub\/)?(media|static)\/.*\\.(ico|css|js|jpg|jpeg|png|gif|tiff|bmp|mp3|ogg|svg|swf|woff|woff2|eot|ttf|otf)$\") {\r\n        unset req.http.Https;\r\n        unset req.http.X-Forwarded-Proto;\r\n        unset req.http.Cookie;\r\n    }\r\n\r\n    return (hash);\r\n}\r\n\r\nsub vcl_hash {\r\n    if (req.http.cookie ~ \"X-Magento-Vary=\") {\r\n        hash_data(regsub(req.http.cookie, \"^.*?X-Magento-Vary=([^;]+);*.*$\", \"\\1\"));\r\n    }\r\n\r\n    # For multi site configurations to not cache each other's content\r\n    if (req.http.host) {\r\n        hash_data(req.http.host);\r\n    } else {\r\n        hash_data(server.ip);\r\n    }\r\n\r\n    # To make sure http users don't see ssl warning\r\n    if (req.http.X-Forwarded-Proto) {\r\n        hash_data(req.http.X-Forwarded-Proto);\r\n    }\r\n    \r\n}\r\n\r\nsub vcl_backend_response {\r\n    if (beresp.http.content-type ~ \"text\") {\r\n        set beresp.do_esi = true;\r\n    }\r\n\r\n    if (bereq.url ~ \"\\.js$\" || beresp.http.content-type ~ \"text\") {\r\n        set beresp.do_gzip = true;\r\n    }\r\n\r\n    # cache only successfully responses and 404s\r\n    if (beresp.status != 200 &amp;&amp; beresp.status != 404) {\r\n        set beresp.ttl = 0s;\r\n        set beresp.uncacheable = true;\r\n        return (deliver);\r\n    } elsif (beresp.http.Cache-Control ~ \"private\") {\r\n        set beresp.uncacheable = true;\r\n        set beresp.ttl = 86400s;\r\n        return (deliver);\r\n    }\r\n\r\n    if (beresp.http.X-Magento-Debug) {\r\n        set beresp.http.X-Magento-Cache-Control = beresp.http.Cache-Control;\r\n    }\r\n\r\n    # validate if we need to cache it and prevent from setting cookie\r\n    # images, css and js are cacheable by default so we have to remove cookie also\r\n    if (beresp.ttl &gt; 0s &amp;&amp; (bereq.method == \"GET\" || bereq.method == \"HEAD\")) {\r\n        unset beresp.http.set-cookie;\r\n        if (bereq.url !~ \"\\.(ico|css|js|jpg|jpeg|png|gif|tiff|bmp|gz|tgz|bz2|tbz|mp3|ogg|svg|swf|woff|woff2|eot|ttf|otf)(\\?|$)\") {\r\n            set beresp.http.Pragma = \"no-cache\";\r\n            set beresp.http.Expires = \"-1\";\r\n            set beresp.http.Cache-Control = \"no-store, no-cache, must-revalidate, max-age=0\";\r\n            set beresp.grace = 1m;\r\n        }\r\n    }\r\n\r\n   # If page is not cacheable then bypass varnish for 2 minutes as Hit-For-Pass\r\n   if (beresp.ttl &lt;= 0s ||\r\n        beresp.http.Surrogate-control ~ \"no-store\" ||\r\n        (!beresp.http.Surrogate-Control &amp;&amp; beresp.http.Vary == \"*\")) {\r\n        # Mark as Hit-For-Pass for the next 2 minutes\r\n        set beresp.ttl = 120s;\r\n        set beresp.uncacheable = true;\r\n    }\r\n    return (deliver);\r\n}\r\n\r\nsub vcl_deliver {\r\n    if (resp.http.X-Magento-Debug) {\r\n        if (resp.http.x-varnish ~ \" \") {\r\n            set resp.http.X-Magento-Cache-Debug = \"HIT\";\r\n        } else {\r\n            set resp.http.X-Magento-Cache-Debug = \"MISS\";\r\n        }\r\n    } else {\r\n        unset resp.http.Age;\r\n    }\r\n\r\n    unset resp.http.X-Magento-Debug;\r\n    unset resp.http.X-Magento-Tags;\r\n    unset resp.http.X-Powered-By;\r\n    unset resp.http.Server;\r\n    unset resp.http.X-Varnish;\r\n    unset resp.http.Via;\r\n    unset resp.http.Link;\r\n}<\/pre>\n<p>SO I need to modify the content of \/etc\/varnish\/default.vcl according to this varnish.vcl.<\/p>\n<pre class=\"lang:default decode:true \">teddy@teddy:\/etc\/nginx\/sites-enabled$ sudo gedit \/etc\/varnish\/default.vcl<\/pre>\n<p>Just copy and paste all content of varnish.vcl to all content in \/etc\/varnish\/default.vcl. Then restart varnish: sudo service varnish restart<br \/>\nNOTE: IN THE DEV SERVER, I PREFER TO DISPLAY THE X-VARNISH AND AGE VARIABLES. SO I MODIFIED \/etc\/varnish\/default.vcl LIKE THIS:<\/p>\n<pre class=\"lang:default decode:true \">...\r\nsub vcl_deliver {\r\n    if (resp.http.X-Magento-Debug) {\r\n        if (resp.http.x-varnish ~ \" \") {\r\n            set resp.http.X-Magento-Cache-Debug = \"HIT\";\r\n        } else {\r\n            set resp.http.X-Magento-Cache-Debug = \"MISS\";\r\n        }\r\n    } else {\r\n        #unset resp.http.Age;\r\n    }\r\n\r\n    unset resp.http.X-Magento-Debug;\r\n    unset resp.http.X-Magento-Tags;\r\n    unset resp.http.X-Powered-By;\r\n    unset resp.http.Server;\r\n    #unset resp.http.X-Varnish;\r\n    unset resp.http.Via;\r\n    unset resp.http.Link;\r\n}<\/pre>\n<p>I also modified \/home\/teddy\/Documents\/works\/fontaineind\/app\/etc\/env.php to include the varnish setting:<\/p>\n<pre class=\"lang:default decode:true \">'http_cache_hosts' =&gt; \r\n  array (\r\n    0 =&gt; \r\n    array (\r\n      'host' =&gt; 'localhost',\r\n      'port' =&gt; '80',\r\n    ),\r\n  ),<\/pre>\n<p>clear and flush the cache. BUT Age still 0 !!!! EVEN WEIRDS, WHEN I CHANGED IN THE MAGENTO ADMIN THAT CACHE APPLICATION IS VARNISH THEN REFRESH THE WEBSITE (ALSO RESTART VARNISH), I GOT THE PAGE LOAD SLOWER!!! WHY?? &#8211;&gt; SOLUTION: I NEED TO EXPORT VCL FILE LIKE ABOVE AND COPY THE CONTENT INTO \/etc\/varnish\/default.vcl<\/p>\n<p>NOW THE VARNISH IS WORKING!!!<br \/>\nTHE SECOND AND MORE REFRESH WOULD MAKE THE PAGE LOAD FASTER. HERE IS THE RESPONSE:<\/p>\n<pre class=\"lang:default decode:true\">Request URL: http:\/\/fontaineind.test\/\r\nRequest Method: GET\r\nStatus Code: 200 OK\r\nRemote Address: 127.0.0.1:80\r\nReferrer Policy: no-referrer-when-downgrade\r\nAccept-Ranges: bytes\r\nAge: 42\r\nCache-Control: no-store, no-cache, must-revalidate, max-age=0\r\nConnection: keep-alive\r\nContent-Encoding: gzip\r\nContent-Length: 117914\r\nContent-Type: text\/html; charset=UTF-8\r\nDate: Fri, 08 Feb 2019 08:03:16 GMT\r\nExpires: -1\r\nPragma: no-cache\r\nVary: Accept-Encoding\r\nX-Content-Type-Options: nosniff\r\nX-Frame-Options: SAMEORIGIN\r\nX-Varnish: 131131 3\r\nX-XSS-Protection: 1; mode=block\r\nAccept: text\/html,application\/xhtml+xml,application\/xml;q=0.9,image\/webp,image\/apng,*\/*;q=0.8\r\nAccept-Encoding: gzip, deflate\r\nAccept-Language: en-US,en;q=0.9\r\nCache-Control: no-cache\r\nConnection: keep-alive\r\nCookie: _ga=GA1.2.153436117.1539751926; __zlcmid=ovhiooeabcbDF8; fastest-popup=true; __atuvc=1%7C48%2C1%7C49; persistent_shopping_cart=1KnMotS8bUecwuFfLz4ZWnjaHxkFBegbdLoTMPtSV1vnmhuz8m; PHPSESSID=a81ae6cda46l21cvknvu7prsb3; form_key=tcwxhKGXlLxlM34K; _gid=GA1.2.1663350196.1549590795; mage-translation-storage=%7B%7D; mage-translation-file-version=%7B%7D; mage-cache-storage=%7B%7D; mage-cache-storage-section-invalidation=%7B%7D; _hjIncludedInSample=1; mage-cache-sessid=true; X-Magento-Vary=1824d10cc0bdb1434527d6e3f2eb93ec93279e70; mage-messages=; _gat=1; private_content_version=54b5be8fb7f0610fc48d2534a06f1e50; section_data_ids=%7B%22cart%22%3A1549613003%2C%22wishlist%22%3A1549613001%2C%22last-ordered-items%22%3A1549613001%2C%22customer%22%3A1549609582%2C%22compare-products%22%3A1549609582%2C%22directory-data%22%3A1549609584%2C%22review%22%3A1549609582%2C%22crosssell_products%22%3A1549609582%2C%22paypal-billing-agreement%22%3A1549609582%7D\r\nHost: fontaineind.test\r\nPragma: no-cache\r\nUpgrade-Insecure-Requests: 1\r\nUser-Agent: Mozilla\/5.0 (X11; Linux x86_64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/72.0.3626.81 Safari\/537.36<\/pre>\n<p>SEE THE AGE = 42 AND X-Varnish: 131131 3<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ref:https:\/\/blog.pusher.com\/speeding-up-your-website-using-varnish\/ https:\/\/www.cyberciti.biz\/faq\/how-to-install-and-configure-varnish-cache-on-ubuntu-linux-16-04-lts\/ https:\/\/www.howtoforge.com\/tutorial\/ubuntu-nginx-varnish\/ https:\/\/amasty.com\/blog\/use-varnish-with-magento-2-for-better-end-user-experience\/ Install Varnish: teddy@teddy:~$ sudo apt-get update teddy@teddy:~$ sudo apt-get install varnish Reading package lists&#8230; Done Building dependency tree Reading state information&#8230; Done The following packages were automatically installed and are no longer required: libtidy5 libzip4 linux-headers-4.15.0-29 linux-headers-4.15.0-29-generic linux-headers-4.15.0-30 linux-headers-4.15.0-30-generic linux-headers-4.15.0-32 linux-headers-4.15.0-32-generic linux-headers-4.15.0-33 linux-headers-4.15.0-33-generic linux-headers-4.15.0-34 linux-headers-4.15.0-34-generic linux-image-4.15.0-29-generic linux-image-4.15.0-30-generic linux-image-4.15.0-32-generic linux-image-4.15.0-33-generic linux-image-4.15.0-34-generic linux-modules-4.15.0-29-generic &hellip; <a href=\"https:\/\/myprojects.advchaweb.com\/index.php\/2019\/02\/08\/install-and-configure-varnish-for-nginx-and-magento-2-on-ubuntu-16-04\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Install and Configure Varnish for Nginx and Magento 2 on Ubuntu 16.04&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[71,98,13,17,78],"tags":[],"class_list":["post-3538","post","type-post","status-publish","format-standard","hentry","category-magento","category-magento-tutorial","category-tutorial","category-ubuntu","category-ubuntu-16-04"],"_links":{"self":[{"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/posts\/3538","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/comments?post=3538"}],"version-history":[{"count":21,"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/posts\/3538\/revisions"}],"predecessor-version":[{"id":3562,"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/posts\/3538\/revisions\/3562"}],"wp:attachment":[{"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/media?parent=3538"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/categories?post=3538"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/tags?post=3538"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}