• Domains
  • Web Hosting
  • WordPress Hosting
  • Reseller Hosting
  • Cloud VPS
  • Dedicated Servers
  • Domains
  • Web Hosting
  • WordPress Hosting
  • Reseller Hosting
  • Cloud VPS
  • Dedicated Servers
home/Knowledge Base/Web Servers/Installing Varnish 4 with Apache 2 on Ubuntu 14.04
Popular Search:Dedicated Server, CentOS, Web Hosting

Installing Varnish 4 with Apache 2 on Ubuntu 14.04

12 views 0 December 27, 2019 aklwebhost

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.

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.

Step 1

Install Apache server and activate it by using the following commands:

sudo apt-get update
sudo apt-get install apache2-mpm-event

You can test Apache’s server status with this command:

sudo service apache2 status

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

sudo service apache2 start

Step 2

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.

sudo apt-get install apt-transport-https
sudo curl https://repo.varnish-cache.org/ubuntu/GPG-key.txt | apt-key add -
echo "deb https://repo.varnish-cache.org/ubuntu/ trusty varnish-4.0" >> /etc/apt/sources.list.d/varnish-cache.list
sudo apt-get update
sudo apt-get install varnish

Step 3

Configure Varnish Cache. Here we are going to change the Varnish server port to 80. Run the following command:

sudo nano /etc/default/varnish

Now look for DAEMON_OPTS=” under Alternative 2, Configuration with VCL. Change the DAEMON_OPTS=” section to match the following lines. This is only a port update.

DAEMON_OPTS="-a :80 \
             -T localhost:6082 \
             -f /etc/varnish/default.vcl \
             -S /etc/varnish/secret \
             -s malloc,256m"

Press CTRL + X, then Y to save the file.

Step 4

Configure Apache. We need to change the listening port of Apache from 80 to 8080.

Edit the ports file by run the following command:

sudo nano /etc/apache2/ports.conf

Change the Listen 80 to Listen 8080.

Next, update the virtual host file…

sudo nano /etc/apache2/sites-available/000-default.conf

… change <VirtualHost *:80> to <VirtualHost *:8080>.

If you have other virtual host files, then they should be updated as well.

Restart both services.

sudo service apache2 restart
sudo service varnish restart

You’re all set. See the following sections for advanced setup tips.

View stats

Run the following command to show Varnish stats:

varnishstat

Advanced VCL settings

You can edit the default.vcl file for various features.

Enable leverage browser caching

To enable browser caching for media files, your vcl_backend_response should match the following configuration.

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

This will improve your site speed and SEO ranking.

Purge cache

To clear the Varnish’s cache, you can change vcl_recv to match the following configuration:

sub vcl_recv {
     if (req.method == "PURGE") {
            return (purge);
     }
 }

After making this change, you can send a curl request in your ssh session with the following format:

curl <domain_name.com> -XPURGE

Here, -XPURGE will send the purge request to the Varnish server.

Tags:Installing Varnish 4 with Apache 2 on Ubuntu 14.04

Was this helpful?

Yes  No
Related Articles
  • Installing Rust on Ubuntu 14.04
  • Using Tango on Ubuntu 14.04
  • Setup Spigot on Ubuntu
  • Setup Fail2ban Ubuntu x64
  • Installing InfluxDB on Ubuntu 14
  • How To Setup Apache on Windows Server
Leave A Comment Cancel reply

Web Servers
  • Installing Varnish 4 with Apache 2 on Ubuntu 14.04
  • How To Setup Apache on Windows Server
  • Setting up IIS on Windows Server
  • Setup NGINX, PHP-FPM, and MariaDB on Debian 8
  • Apache Virtual Hosts on Ubuntu 14.04 LTS
  • Install Lighttpd with PHP5 and MySQL (LLMP Stack) on Ubuntu 14.04
View All 37  
Popular Articles
  • Using StrongSwan for IPSec VPN on CentOS 7
  • Disabling SSDP (Linux / Windows)
  • Can I pay by Western Union?
  • Can a Coupon Code Discount Be Carried Forward While I Upgrade My VPS Account
  • Can I pay multiple due invoices using a single transaction?
KB Categories
  • Billing
  • Cloud Hosting
  • CMS Hosting
  • cPanel/WHM Control Panel Guide
  • Dedicated Servers
    • AMD Opteron 6272
    • Arch
    • Backup Storage
    • Bandwidth
    • Basic Security
    • BSD
    • CentOS
    • Containers
    • CoreOS
    • DDoS Protection
    • Debian
    • Dedicated Server Control Panel
    • Intel Core i5 3550
    • Intel Core i5 4570
    • Intel Core i7 3770
    • Intel Core i7 4770
    • Intel Xeon E3 1230 V3
    • Intel Xeon E3 1245 V2
    • IP Space
    • Linux Guides
    • Minecraft
    • Networking
    • Server Apps
    • Server Troubleshooting
    • Ubuntu
    • Windows Guides
    • Windows Server 2008
    • Windows Server 2012
  • Domain Names
  • Email Support Documentation
    • Setup IMAP or POP
    • User Features – How To
    • Webmail – How To
  • FTP (File Transfer Protocol
    • CuteFTP Guide
    • FileZilla Guide
  • Game Servers
  • MySQL and MariaDB
  • Node.js
  • Plesk Web Hosting Guide
  • VPS Server
  • Web Servers

  Installing Ubuntu Server on Drives Larger Than 2 TB

Nginx Reverse Proxy with Ghost on Ubuntu 14.04  

  • Privacy Policy
  • Terms of Use
  • © 2022 AKLWEB HOST LLC, All Rights Reserved.

Popular Search:Dedicated Server, CentOS, Web Hosting