Это лак хит? - PullRequest
       36

Это лак хит?

0 голосов
/ 17 октября 2018

У меня проблема с Varnish, установленным с Magento 2, я прошел этот урок https://slack -redir.net / link? Url = https% 3A% 2F% 2Fwww.techrepublic.com% 2Farticle% 2Fhow-to-speed-up-apache-with-varnish-http-cache% 2F

Я использовал следующую команду:

curl -I localhost/folder1/folder2
HTTP/1.1 200 OK
Date: Tue, 16 Oct 2018 22:23:50 GMT
Server: Apache/2.4.18 (Ubuntu)
Last-Modified: Fri, 16 Jun 2017 15:47:07 GMT
Vary: Accept-Encoding
Content-Type: text/html
X-Varnish: 131250
Age: 0
Via: 1.1 varnish-v4
ETag: W/"2c39-55215b29954a5-gzip"
Accept-Ranges: bytes
Connection: keep-alive

Я обычно вижу в примерах, что она должнаесть HIT, но я его не вижу, возможно, он плохо настроен, также, когда я нажимаю на ссылку на моем сайте, это займет 6 секунд, затем я нажимаю на ту же ссылку и такое же количество времени, поэтому это может не работать

Мои файлы:

Файл /etc/varnish/default.vcl

#
# This is an example VCL file for Varnish.
#
# It does not do anything by default, delegating control to the
# builtin VCL. The builtin VCL is called when there is no explicit
# return statement.
#
# See the VCL chapters in the Users Guide at https://www.varnish-cache.org/docs/
# and https://www.varnish-cache.org/trac/wiki/VCLExamples for more examples.

# Marker to tell the VCL compiler that this VCL has been adapted to the
# new 4.0 format.
vcl 4.0;

# 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.
    #
    # Typically you clean up the request here, removing cookies you don't need,
    # rewriting the request, etc.
}

sub vcl_backend_response {
    # Happens after we have read the response headers from the backend.
    #
    # Here you clean the response headers, removing silly Set-Cookie headers
    # and other mistakes your backend does.
}

sub vcl_deliver {
    # Happens when we have all the pieces we need, and are about to send the
    # response to the client.
    #
    # You can do accounting or modifying the final object here.
}

Файл 000-default.conf:

etc/apache2/sites-available/000-default.conf
<VirtualHost *:8080>
blablablabl
</VirtualHost>

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

Файл / lib/systemd/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,256m
ExecReload=/usr/share/varnish/reload-vcl
ProtectSystem=full
ProtectHome=true
PrivateTmp=true
PrivateDevices=true

[Install]
WantedBy=multi-user.target

porst.conf file

/etc/apache2/ports.conf
Listen 8080
#blablabla

Ответы [ 2 ]

0 голосов
/ 21 ноября 2018

Вы можете определить HIT или MISS кэша, добавив некоторый код в раздел sub vcl_deliver /etc/varnish/default.vcl.

if (obj.hits > 0) {
    set resp.http.Cache-Tags = "HIT";
}
else {
    set resp.http.Cache-Tags = "MISS";
}
  1. и добавьте приведенный выше код в vcl_deliver из / etc /varnish / default.vcl.
  2. перезагрузить / перезапустить лак.
  3. Curl -I ваш запрос
  4. Искать Cache-Tags в заголовке ответа.

Метод 2:

Вы можете выполнить команду на сервере лака и проверить, что запросы выполнены или пропущены

sudo varnishncsa -F '% U% q% {Varnish: hitmiss} x'

Если вы введете указанную выше команду и зайдете на веб-сайт, он покажет, что вы пропустили или попали в командную строку.

0 голосов
/ 17 октября 2018

Это не попадание в кеш.

Чтобы проверить, было ли попадание в кеш, проверьте значение X-Varnish: 131250.Одно число означает пропуск кэша, два числа, например, X-Varnish: 131250 12345 означает попадание в кэш.

Вам необходимо загрузить специальный VCL-файл Magento от администратора Magento, а не использовать файл по умолчанию.

...