Zum Inhalt springen

Varnish Cache auf ubuntu installieren: Unterschied zwischen den Versionen

Aus Computech CMS Wiki
Simon Zeberli (Diskussion | Beiträge)
Die Seite wurde neu angelegt: „==How To Install and Configure Varnish with Apache on Ubuntu 12.04== Apache can be installed on your VPS with a single command from the apt-get repository. su…“
 
Simon Zeberli (Diskussion | Beiträge)
Keine Bearbeitungszusammenfassung
Zeile 1: Zeile 1:
https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-varnish-with-apache-on-ubuntu-12-04--3
==How To Install and Configure Varnish with Apache on Ubuntu 12.04==
==How To Install and Configure Varnish with Apache on Ubuntu 12.04==
Apache can be installed on your VPS with a single command from the apt-get repository.
Apache can be installed on your VPS with a single command from the apt-get repository.

Version vom 4. Mai 2015, 19:57 Uhr

https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-varnish-with-apache-on-ubuntu-12-04--3

How To Install and Configure Varnish with Apache on Ubuntu 12.04

Apache can be installed on your VPS with a single command from the apt-get repository.

sudo apt-get install apache2

Step One—Install Varnish

You can start that process by grabbing the repository:

sudo curl http://repo.varnish-cache.org/debian/GPG-key.txt | sudo apt-key add -

The next step is to add the repository to the list of apt sources. Go ahead and open up that file.

sudo nano /etc/apt/sources.list

Once inside the file, add the varnish repository to the list of sources.

deb http://repo.varnish-cache.org/ubuntu/ lucid varnish-3.0

Save and exit. Finally, update apt-get and install varnish.

sudo apt-get update
sudo apt-get install varnish

Step Two—Configure Varnish

Once you have both apache and varnish installed, you can start to configure them to ease the load on your server from future visitors. Varnish will serve the content on port 80, while fetching it from apache which will run on port 8080. Let’s go ahead and start setting that up by opening the /etc/default/varnish file:

sudo nano /etc/default/varnish

Uncomment all of the lines under “DAEMON_OPTS”—under Alternative 2, and make the configuration match the following code:

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

Once you save and exit out of that file, open up the default.vcl file:

sudo nano /etc/varnish/default.vcl

This file tells varnish where to look for the webserver content. Although Apache listens on port 80 by default, we will change the settings for it later. Within this file, we will tell varnish to look for the content on port 8080. The configuration should like this:

backend default {
   .host = "127.0.0.1";
   .port = "8080";
}

Step Three—Configure Apache

sudo nano /etc/apache2/ports.conf

Change the port number for both the NameVirtualHost and the Listen line to port 8080, and the virtual host should only be accessible from the localhost. The configuration should look like this:

NameVirtualHost 127.0.0.1:8080
Listen 127.0.0.1:8080

Change these settings in the default virtual host file as well:

sudo nano /etc/apache2/sites-available/default

The Virtual Host should also be set to port 8080, and updated line looks like this:

<VirtualHost 127.0.0.1:8080>

Save and exit the file and proceed to restart Apache and Varnish to make the changes effective.

sudo service apache2 restart
sudo service varnish restart

Accessing your domain should instantly take you to the varnish cached version, and you can see the details of varnish’s workings with this command:

varnishstat