Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794
{"id":2885,"date":"2019-12-27T06:58:36","date_gmt":"2019-12-27T06:58:36","guid":{"rendered":"https:\/\/support.aklwebhost.com\/?post_type=manual_kb&p=2885"},"modified":"2019-12-27T06:58:36","modified_gmt":"2019-12-27T06:58:36","slug":"installing-varnish-4-with-apache-2-on-ubuntu-14-04","status":"publish","type":"manual_kb","link":"https:\/\/support.aklwebhost.com\/knowledgebase\/installing-varnish-4-with-apache-2-on-ubuntu-14-04\/","title":{"rendered":"Installing Varnish 4 with Apache 2 on Ubuntu 14.04"},"content":{"rendered":"

Apache is popular web server used by most web hosting companies. Varnish cache is an HTTP accelerator and reverse proxy. We can use Varnish with any HTTP server. In this example, we will be using Apache 2.<\/p>\n

As a web server, Apache can use a considerable amount of server resources to serve pages. If you are running a high-traffic website, then you might need an HTTP accelerator to boost server performance. Varnish will help you with that.<\/p>\n

Step 1<\/h3>\n

Install Apache server and activate it by using the following commands:<\/p>\n

sudo apt-get update\r\nsudo apt-get install apache2-mpm-event\r\n<\/code><\/pre>\n

You can test Apache’s server status with this command:<\/p>\n

sudo service apache2 status\r\n<\/code><\/pre>\n

If the service is running, “apache2 is running” will be printed to your terminal. Otherwise, you can start the service with this command:<\/p>\n

sudo service apache2 start\r\n<\/code><\/pre>\n

Step 2<\/h3>\n

Install the latest stable version of Varnish 4. This version is not available in Ubuntu Repository by default, so you need to run the following commands to install it.<\/p>\n

sudo apt-get install apt-transport-https\r\nsudo curl https:\/\/repo.varnish-cache.org\/ubuntu\/GPG-key.txt | apt-key add -\r\necho \"deb https:\/\/repo.varnish-cache.org\/ubuntu\/ trusty varnish-4.0\" >> \/etc\/apt\/sources.list.d\/varnish-cache.list\r\nsudo apt-get update\r\nsudo apt-get install varnish\r\n<\/code><\/pre>\n

Step 3<\/h3>\n

Configure Varnish Cache. Here we are going to change the Varnish server port to 80. Run the following command:<\/p>\n

sudo nano \/etc\/default\/varnish\r\n<\/code><\/pre>\n

Now look for\u00a0DAEMON_OPTS=”<\/strong>\u00a0under\u00a0Alternative 2, Configuration with VCL<\/strong>. Change the\u00a0DAEMON_OPTS=”<\/strong>\u00a0section to match the following lines. This is only a port update.<\/p>\n

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\"\r\n<\/code><\/pre>\n

Press\u00a0CTRL<\/strong>\u00a0+\u00a0X<\/strong>, then\u00a0Y<\/strong>\u00a0to save the file.<\/p>\n

Step 4<\/h3>\n

Configure Apache. We need to change the listening port of Apache from 80 to 8080.<\/p>\n

Edit the ports file by run the following command:<\/p>\n

sudo nano \/etc\/apache2\/ports.conf\r\n<\/code><\/pre>\n

Change the\u00a0Listen 80<\/strong>\u00a0to\u00a0Listen 8080<\/strong>.<\/p>\n

Next, update the virtual host file…<\/p>\n

sudo nano \/etc\/apache2\/sites-available\/000-default.conf\r\n<\/code><\/pre>\n

… change\u00a0<VirtualHost *:80><\/strong>\u00a0to\u00a0<VirtualHost *:8080><\/strong>.<\/p>\n

If you have other virtual host files, then they should be updated as well.<\/p>\n

Restart both services.<\/p>\n

sudo service apache2 restart\r\nsudo service varnish restart\r\n<\/code><\/pre>\n

You’re all set. See the following sections for advanced setup tips.<\/p>\n

View stats<\/h3>\n

Run the following command to show Varnish stats:<\/p>\n

varnishstat\r\n<\/code><\/pre>\n

Advanced VCL settings<\/h3>\n

You can edit the\u00a0default.vcl<\/code>\u00a0file for various features.<\/p>\n

Enable leverage browser caching<\/h4>\n

To enable browser caching for media files, your\u00a0vcl_backend_response<\/code>\u00a0should match the following configuration.<\/p>\n

sub vcl_backend_response {\r\n    if (bereq.url ~ \"\\.(png|gif|jpg|swf|css|js)$\") {\r\n    unset beresp.http.set-cookie;\r\n    set beresp.http.cache-control = \"max-age = 2592000\";\r\n  }\r\n}\r\n<\/code><\/pre>\n

This will improve your site speed and SEO ranking.<\/p>\n

Purge cache<\/h4>\n

To clear the Varnish’s cache, you can change\u00a0vcl_recv<\/code>\u00a0to match the following configuration:<\/p>\n

sub vcl_recv {\r\n     if (req.method == \"PURGE\") {\r\n            return (purge);\r\n     }\r\n }\r\n<\/code><\/pre>\n

After making this change, you can send a curl request in your ssh session with the following format:<\/p>\n

curl <domain_name.com> -XPURGE\r\n<\/code><\/pre>\n

Here,\u00a0-XPURGE<\/code>\u00a0will send the purge request to the Varnish server.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"","format":"standard","manualknowledgebasecat":[109,247],"manual_kb_tag":[443],"_links":{"self":[{"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb\/2885"}],"collection":[{"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb"}],"about":[{"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/types\/manual_kb"}],"author":[{"embeddable":true,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/comments?post=2885"}],"version-history":[{"count":1,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb\/2885\/revisions"}],"predecessor-version":[{"id":2886,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb\/2885\/revisions\/2886"}],"wp:attachment":[{"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/media?parent=2885"}],"wp:term":[{"taxonomy":"manualknowledgebasecat","embeddable":true,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manualknowledgebasecat?post=2885"},{"taxonomy":"manual_kb_tag","embeddable":true,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb_tag?post=2885"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}