{"id":46,"date":"2014-10-12T20:21:00","date_gmt":"2014-10-12T20:21:00","guid":{"rendered":"https:\/\/www.tech-and-dev.com\/blog\/2014\/10\/12\/installing-varnish-with-virtualmin\/"},"modified":"2021-02-22T01:02:50","modified_gmt":"2021-02-22T01:02:50","slug":"installing-varnish-on-virtualmin","status":"publish","type":"post","link":"https:\/\/www.tech-and-dev.com\/blog\/2014\/10\/installing-varnish-on-virtualmin.html","title":{"rendered":"Installing Varnish With Virtualmin"},"content":{"rendered":"<div dir=\"ltr\" style=\"text-align: left;\">\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2021\/02\/varnish.jpg\"><img decoding=\"async\" title=\"Varnish Logo\" src=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2021\/02\/varnish.jpg\" alt=\"Varnish Logo\" border=\"0\" \/><\/a><\/div>\n<h2 style=\"text-align: left;\">What is Varnish<\/h2>\n<p>&nbsp;<\/p>\n<div style=\"text-align: justify;\">Varnish is an HTTP accelerator and a reverse proxy caching web application.<\/div>\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"text-align: justify;\">Varnish is usually installed in front of the webserver such as Apache and Nginx, and cache their content in order to deliver it fast when a request is made.<\/div>\n<div style=\"text-align: justify;\"><a name=\"more\"><\/a><\/div>\n<div style=\"text-align: justify;\">I couldn&#8217;t find any good tutorial on installing varnish with virtualmin so I decided to test and post about it.<\/div>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2021\/02\/varnish-explanation.png\"><img loading=\"lazy\" decoding=\"async\" title=\"Varnish Diagram\" src=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2021\/02\/varnish-explanation.png\" alt=\"Varnish Explanation\" width=\"400\" height=\"180\" border=\"0\" \/><\/a><\/div>\n<p>&nbsp;<\/p>\n<h2 style=\"text-align: left;\">Installing dependencies<\/h2>\n<blockquote><p>yum install -y gcc make automake autoconf libtool ncurses-devel libxslt groff pcre-devel libedit libedit-devel<\/p><\/blockquote>\n<p>Varnish 4 requires jemalloc to work<\/p>\n<blockquote><p>rpm -Uvh https:\/\/dl.fedoraproject.org\/pub\/epel\/7\/x86_64\/j\/jemalloc-3.6.0-1.el7.x86_64.rpm<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<h2 style=\"text-align: left;\">Installing Varnish<\/h2>\n<p>The below is for CentOS 6. Varnish for other distros can be found on <a href=\"http:\/\/repo.varnish-cache.org\/\" target=\"_blank\" rel=\"nofollow noopener\">http:\/\/repo.varnish-cache.org\/<\/a><\/p>\n<p>Login to SSH, and issue the following commands:<\/p>\n<blockquote><p>rpm -Uvh http:\/\/repo.varnish-cache.org\/redhat\/varnish-4.0\/el6\/noarch\/varnish-release\/varnish-release-4.0-4.el6.noarch.rpm<\/p><\/blockquote>\n<blockquote><p>yum install varnish<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<h2 style=\"text-align: left;\"><\/h2>\n<h2 style=\"text-align: left;\">Configuring varnish<\/h2>\n<div style=\"text-align: justify;\">Varnish is installed in front of the webserver, so it should listen on port 80 to accept the web requests.<\/div>\n<blockquote><p>vi \/etc\/sysconfig\/varnish<\/p><\/blockquote>\n<p>Set\u00a0 VARNISH_LISTEN_PORT to 80<\/p>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2021\/02\/varnish-listen-port.png\"><img decoding=\"async\" title=\"Varnish Listening Port\" src=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2021\/02\/varnish-listen-port.png\" alt=\"Varnish Listening Port\" border=\"0\" \/><\/a><\/div>\n<p>&nbsp;<\/p>\n<div style=\"text-align: justify;\">Since varnish will be listening on port 80, the webserver will have to listen on a different port. In this tutorial, I will use port 8080.<\/div>\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"text-align: justify;\">So varnish will fetch the content from the webserver, and cache it. In order for varnish to know which port the webserver is listening to, we modify \/etc\/varnish\/default.vcl<\/div>\n<blockquote><p>vi \/etc\/varnish\/default.vcl<\/p><\/blockquote>\n<div style=\"text-align: justify;\">And set the port to 8080. Then set the IP to your server&#8217;s external IP. Setting it to 127.0.0.1 will not work on virtualmin by default, since virtualmin uses the external IP when creating a virtual host.<\/div>\n<div style=\"text-align: justify;\">(Replace xxx.xxx.xxx.xxx by your external IP)<\/div>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2021\/02\/varnish-webserver-location.png\"><img decoding=\"async\" title=\"Apache and Varnish listening ports\" src=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2021\/02\/varnish-webserver-location.png\" alt=\"Apache and Varnish listening ports\" border=\"0\" \/><\/a><\/div>\n<p>&nbsp;<\/p>\n<h2 style=\"text-align: left;\">Changing Virtualhosts to new Web server port (8080)<\/h2>\n<div style=\"text-align: justify;\">If you already have virtualhosts created, you will have to modify them all, one by one, by going to:<\/div>\n<div style=\"text-align: justify;\">Virtual Server =&gt; Server Configuration =&gt; Change IP Address =&gt; Set <i>New HTTP port<\/i> to <b>8080<\/b><\/div>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2021\/02\/virtualmin-change-ip-address.png\"><img decoding=\"async\" title=\"Virtualmin virtualhost\" src=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2021\/02\/virtualmin-change-ip-address.png\" alt=\"changing the port of virtualhost in virtualmin for varnish\" border=\"0\" \/><\/a><\/div>\n<p>&nbsp;<\/p>\n<h2 style=\"text-align: left;\">Change the port the webserver is listening to:<\/h2>\n<p>Webmin =&gt; Servers =&gt; Apache Webserver =&gt; Make sure all the virtual hosts are not listening on port 80<br \/>\nGo to Global Configuration Tab =&gt; Network and Configuration =&gt; Remove ALL the entries that has port 80 in it.<br \/>\nMake sure xxx.xxx.xxx.xxx is your IP Address<\/p>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2021\/02\/virtualmin-networking-address.png\"><img decoding=\"async\" title=\"Virtualmin networking and addresses\" src=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2021\/02\/virtualmin-networking-address.png\" alt=\"Changing apache port for varnsih\" border=\"0\" \/>\u00a0<\/a><\/div>\n<div style=\"clear: both; text-align: center;\"><\/div>\n<h2 style=\"text-align: left;\">Restart the Servers:<\/h2>\n<blockquote><p>service httpd restart<br \/>\nservice varnish restart<\/p><\/blockquote>\n<p>All your sites should now be running.<\/p>\n<h2 style=\"text-align: left;\">Configure Varnish to Start after a Reboot<\/h2>\n<p>Go to Webmin =&gt; System =&gt; Bootup and Shutdown =&gt; Choose Varnish =&gt; Click Start on Boot<\/p>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2021\/02\/varnish-start-on-boot.png\"><img loading=\"lazy\" decoding=\"async\" title=\"Varnish on Startup\" src=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2021\/02\/varnish-start-on-boot.png\" alt=\"Configuring varnish to start after a reboot\" width=\"400\" height=\"109\" border=\"0\" \/><\/a><\/div>\n<p>&nbsp;<\/p>\n<h2 style=\"text-align: left;\"><\/h2>\n<h2 style=\"text-align: left;\">Edit Server Templates<\/h2>\n<div style=\"text-align: justify;\">Edit the Server templates, so that the next time you create a new virtual host, it will be listening on port 80.<\/div>\n<div style=\"text-align: justify;\">Virtualmin =&gt; System Settings =&gt; Server Templates =&gt; Default Settings =&gt; Apache Website =&gt; Change &#8220;<b>Port number for virtual hosts<\/b>&#8221; to 8080 and then click &#8220;Save&#8221;.<\/div>\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2021\/02\/virtualmin-server-template-8080.png\"><img decoding=\"async\" title=\"Virtualmin Template\" src=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2021\/02\/virtualmin-server-template-8080.png\" alt=\"Editing virtualmin template for apache in order for varnish to work\" border=\"0\" \/><\/a><\/div>\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"text-align: justify;\">If you have more custom templates, you will need to edit them all.<\/div>\n<div style=\"text-align: justify;\"><\/div>\n<p>&nbsp;<\/p>\n<h2 style=\"text-align: left;\">Check Varnish Performance<\/h2>\n<p>In SSH type:<\/p>\n<blockquote><p>varnishstat<\/p><\/blockquote>\n<div style=\"text-align: justify;\">In this tutorial, I&#8217;m using Apache as a webserver, but it should work well on Nginx or any other webserver.<\/div>\n<p><b>Any questions? Please let me know!<\/b><\/p>\n<p>&nbsp;<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>What is Varnish &nbsp; Varnish is an HTTP accelerator and a reverse proxy caching web application. Varnish is usually installed in front of the webserver such as Apache and Nginx, and cache their content in order to deliver it fast when a request is made. I couldn&#8217;t find any good tutorial on installing varnish with [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[17,6,53,41],"tags":[],"class_list":["post-46","post","type-post","status-publish","format-standard","hentry","category-centos","category-linux","category-varnish","category-virtualmin"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts\/46","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/comments?post=46"}],"version-history":[{"count":1,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts\/46\/revisions"}],"predecessor-version":[{"id":279,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts\/46\/revisions\/279"}],"wp:attachment":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/media?parent=46"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/categories?post=46"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/tags?post=46"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}