Varnish HTTP-kiihdyttimen asennus ja konfigurointi

Huomio:

Tätä konfiguraatiota käytettiin tutkimuksessa, jossa mitattiin kolmen vapaan ohjelmiston HTTP-kiihdyttimen suorituskykyä staattisten ja dynaamisten verkkosivusisältöjen tarjoamisessa.

Konfiguraatio ei ole tarkoitettu sellaisenaan suoraan käyttöönotettavaksi jo olemassa olevaan ympäristöön. Älä siis kopioi huolimattomasti tätä tuotantoon, vaan kokeile ensin testiympäristössä.

Tutkimuksen tarkemmat tiedot löytyvät tästä artikkelista:

Vapaan ohjelmiston HTTP-kiihdyttimien vaikutus verkkosivujen suorituskykyyn (Varnish, Squid, Nginx)


Asennus terminaalin komennoilla:

sudo apt update
sudo apt install varnish

sudo nano /etc/default/varnish
sudo nano /lib/systemd/system/varnish.service

sudo systemctl daemon-reload
sudo systemctl restart varnish

sudo nano /etc/varnish/default.vcl
sudo systemctl restart varnish

cd /etc/apache2/mods-available/
sudo a2enmod rewrite
sudo systemctl restart apache2

sudo systemctl reload varnish
sudo systemctl restart varnish

Varnishin pääkonfiguraatio /etc/default/varnish:

# Should we start varnishd at boot?  Set to "no" to disable.
START=yes

# Maximum number of open files (for ulimit -n)
NFILES=131072

# Maximum locked memory size (for ulimit -l)
MEMLOCK=82000

DAEMON_OPTS="-a :80 \

             -T localhost:6082 \
             -f /etc/varnish/default.vcl \
             -S /etc/varnish/secret \
             -s malloc,1024m"

Varnish-servicen määritykset /lib/system/system/varnish.service:

[Unit]
Description=Varnish HTTP accelerator
Documentation=https://www.varnish-cache.org/docs/4.1/ man:varnishd

[Service]
Type=simple
LimitNOFILE=131072
LimitMEMLOCK=82000
ExecStart=/usr/sbin/varnishd -j unix,user=vcache -F -a :80 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,1024m
ExecReload=/usr/share/varnish/varnishreload
ProtectSystem=full
ProtectHome=true
PrivateTmp=true
PrivateDevices=true

[Install]
WantedBy=multi-user.target

Varnishin VCL-konfiguraatio /etc/varnish/default.vcl:

# Default backend definition. Set this to point to your content server.

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

sub vcl_recv {
    # Happens before we check if we have this in cache already.
# exclude wordpress url
if (req.url ~ "wp-admin|wp-login") {
    return (pass);
}

#unsetting wordpress cookies
  set req.http.cookie = regsuball(req.http.cookie, "wp-settings-\d+=[^;]+(; )?", "");
  set req.http.cookie = regsuball(req.http.cookie, "wp-settings-time-\d+=[^;]+(; )?", "");
  set req.http.cookie = regsuball(req.http.cookie, "wordpress_test_cookie=[^;]+(; )?", "");

  if (req.http.cookie == "") {
    unset req.http.cookie;
  }
}

sub vcl_backend_response {
    # Happens after we have read the response headers from the backend.

    if (beresp.ttl == 120s) {
            set beresp.ttl = 1h;
    }
}

sub vcl_deliver {
    # Happens when we have all the pieces we need, and are about to send the
    # response to the client.
}

TÄTÄ DOKUMENTTIA SAA KOPIOIDA JA MUOKATA GNU GENERAL PUBLIC LICENSE (VERSIO 3 TAI UUDEMPI) MUKAISESTI. HTTP://WWW.GNU.ORG/LICENSES/GPL.HTML
MARKUS PYHÄRANTA

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top
Scroll to Top