AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题

问题[varnish](server)

Martin Hope
NicoAdrian
Asked: 2024-11-07 23:12:46 +0800 CST

Varnish 打开文件数量非常多

  • 8

这是我的 Varnish 配置:

/usr/sbin/varnishd \
      -a 127.0.0.1:6081 \
      -T 127.0.0.1:6082 \
      -f /varnish/default.vcl \
      -P %t/%N/varnishd.pid \
      -s malloc,4G \
      -p thread_pools=12 -p thread_pool_min=250 -p default_ttl=1 -p default_grace=0 -p timeout_idle=1800

因此 12 * 250 = 3000 个线程。使用此设置,我最终打开了超过 400k 个文件。

将线程数减少到最低限度确实会大大减少打开文件的数量。

问题是:这怎么可能?每个 Varnish 线程打开这么多文件是正常的吗?

编辑:这是我的 VCL 文件:

vcl 4.1;

backend someBackend {
    .host = "someBackend.net";
    .connect_timeout = 2s;
    .first_byte_timeout = 5s;
    .between_bytes_timeout = 5s;
}

sub vcl_recv {
    # Remove Varnish from X-Forwarded-For (set by Nginx)
    set req.http.X-Forwarded-For = regsub(req.http.X-Forwarded-For, ",[^,]+$", "");
}

sub vcl_backend_fetch {
    # Hide Varnish token
    unset bereq.http.X-Varnish;
}

sub vcl_backend_response {
    unset beresp.http.Vary;
}

sub vcl_deliver {
    unset resp.http.Via;
    unset resp.http.X-Varnish;
}
varnish
  • 1 个回答
  • 112 Views
Martin Hope
Predaytor
Asked: 2023-10-19 21:33:31 +0800 CST

漆。如何使用 cookie 根据区域设置进行重定向?

  • 5

我需要为多语言站点实现基于 cookie 的重定向逻辑。我有 Next.js 中间件的工作代码,但不幸的是它无法在 Docker 的独立设置中工作(我不使用 Vercel)。

import { NextRequest, NextResponse } from 'next/server';

export const config = {
    matcher: [
        /*
         * Match all request paths except for the ones starting with:
         * - api (API routes)
         * - _next (static files)
         * - URLs ending with a file extension (e.g., .html, .js, .css, etc.)
         */
        '/((?!api|_next|\\.\\.).+)',
    ],
};

export function middleware(request: NextRequest) {
    const { pathname, search, defaultLocale, locale } = request.nextUrl;

    const localeCookie = request.cookies.get('NEXT_LOCALE')?.value;

    if (!localeCookie && locale !== defaultLocale) {
        return NextResponse.redirect(new URL(`/${defaultLocale}${pathname}${search}`, request.url));
    }

    if (localeCookie && locale !== localeCookie) {
        return NextResponse.redirect(new URL(`/${localeCookie}${pathname}${search}`, request.url));
    }

    return NextResponse.next();
}

我想实现 Varnish 设置而不是 Next.js 解决方案:

vcl 4.1;

import cookie;

sub vcl_recv {
    ...

    if (req.url ~ "^/_next" || req.url ~ "/api/" || req.url ~ "/\.(.*)$/") {
        return (pass);
    }

    # Extract the locale from the URL, the default locale is hidden
    if (req.url ~ "^/[a-z]{2}/") {
        set req.http.locale = regsub(req.url, "^/([a-z]{2})(/.*)?$", "\1");
    } else {
        set req.http.locale = "";
    }

    # Extract NEXT_LOCALE cookie
    if (req.http.cookie) {
        cookie.parse(req.http.cookie);
        set req.http.localeCookie = cookie.get("NEXT_LOCALE");
        set req.http.cookie = cookie.get_string();
    }

    // If locale is specified and NEXT_LOCALE is missing, redirect to the default locale.
    if (req.http.locale != "" && !req.http.localeCookie) {
        # set req.http.X-Redirect-Url = ...;
        return (synth(302));
    }
    // If NEXT_LOCALE is present and the locale is not equal to the locale from cookie, then redirect to the cookie locale
    else if (req.http.locale != "" && req.http.locale != req.http.localeCookie) {
        # set req.http.X-Redirect-Url = ...;
        return (synth(302));
    }

    ...

    return (hash);
}

sub vcl_synth {
    # Perform the actual redirection based on the X-Redirect-Url header
    if (resp.status == 302 && req.http.X-Redirect-Url) {
        set resp.http.location = req.http.X-Redirect-Url;
        set resp.reason = "Moved";
        return (deliver);
    }
}
varnish
  • 2 个回答
  • 128 Views
Martin Hope
Toon Spin
Asked: 2023-02-07 01:27:21 +0800 CST

Varnish 6 bans_persisted_bytes 膨胀,但内存使用情况良好

  • 5

在我负责的 Varnish 6 服务器中,有很多禁令的短暂爆发。这些是我无法修改的应用程序的结果。这导致 RAM 使用量很快失控,但我已经能够通过设置ban_cutoff为 100 来解决这个问题。这似乎很好地解决了这个问题。RAM 的使用现在得到了很好的控制。

然而,bans_persisted_bytes每次爆发仍然快速增长并且似乎根本没有下降。在我写这篇文章时,它大约为 29GiB,但主机(一台 Debian Bullseye 机器)的总内存使用量约为 1.6 GiB。

我应该担心的大小bans_persisted_bytes吗?毕竟,它似乎没有使用 RAM。但我想知道如果不是 RAM 使用情况,这个值意味着什么。

我希望有人能对此有所了解。TIA!

varnish
  • 1 个回答
  • 13 Views
Martin Hope
Budianto IP
Asked: 2022-12-16 22:16:36 +0800 CST

清漆 - 分离和附加 cookie

  • 5

首先,我想知道这是否可能。

所以,我可以看到如果 Varnish 有 cookie,它就不会缓存对象。

我在考虑当传入请求有 cookie 时,Varnish 会将它们存储在变量中并删除这些 cookie,然后让它通过后端。后端完成处理后,Varnish 会将 cookie 放回。

这是可能的吗?

如果是,vcl 是什么样子的?

varnish
  • 1 个回答
  • 18 Views
Martin Hope
Budianto IP
Asked: 2022-12-15 20:43:35 +0800 CST

如何绕过基于特定标头的清漆缓存

  • 5

自 2 天前以来我一直在研究这个,但没有运气。

所以,基本上,我想绕过特定传入请求 URL 的清漆缓存。

我已经定义了这个规则:

sub vcl_recv {
     if (req.url ~ "/en/reading-books/") { return(pass); }
}

但是当我刷新页面时,它仍然被缓存,响应头返回这些:

via: 1.1 varnish-v4
x-varnish: 2

这个后台运行的命令产生输出:

varnishncsa -F '%{Host}i %h %l %u %t "%r" %s %b "%{Referer}i" "%{User-agent}i"'

我在这里错过了什么?非常感谢任何指点。

varnish
  • 1 个回答
  • 33 Views
Martin Hope
BJaz
Asked: 2022-10-20 00:42:50 +0800 CST

Varnish 7.2 CLI 远程登录日志

  • 5

我升级到 varnish 7.2,现在它将 varnishd 的日志转储到 Centos 8 上的 /var/log/messages 中,并且无法弄清楚如何更改其日志的位置!任何线索将不胜感激。

以下是日志示例: varnishd[2327]: CLI telnet ::1 54416 ::1 38535 Wr 200 Backend name ****

varnish centos8
  • 1 个回答
  • 22 Views
Martin Hope
Ian Pringle
Asked: 2022-04-08 04:30:36 +0800 CST

`.port` 后端与 Varnish 中`.host` 后端的优缺点

  • 0

在工作中,我们有一个清漆集群。所有远程后端都向我们提供该.host值(我认为这是必需的),但本地后端的所有配置,即在 config/varnishd 所在的服务器上运行的后端,都使用该.path值。今天早上我遇到了一个清漆服务器的问题,基本上由 引用的套接字.path不存在,所以它不会启动。我尝试了各种方法来恢复套接字,但在没有奏效后,我将清漆配置切换为使用该.backend值。我看到这是一个好处,因为我现在可以轻松地维护一个集中的清漆配置,而不必担心在每个服务器的基础上编译每个配置(即.host从后端删除与特定服务器相对应的行)。

使用套接字连接到本地清漆集群是否有显着的好处(如果这是一个因素,则使用挂接进行 SSL 终止)?如果一切都是平等的,我认为 using.host值是一个更好的选择,因为它使推送配置更新变得更加简单。

varnish
  • 1 个回答
  • 20 Views
Martin Hope
nikc.org
Asked: 2022-03-18 14:14:20 +0800 CST

更新 Varnish ESI 的请求 cookie,包括来自初始 `beresp` 的请求

  • 0

我有一个以 Varnish 服务器为前端的应用程序。部分页面使用 ESI 包含呈现。

我的问题是上游响应包含一个加密的会话 cookie,其中包含一个 CSRF 令牌(根本没有服务器端会话存储)。

对于初始请求(请求中没有 cookie),ESI 请求将不包含由上游服务器的第一个响应设置的 cookie。

我已经尝试req.http.Cookie在vcl_deliver钩子中设置,因为它是请求流中我发现两者都可以读写的唯一req位置res。但是,使用 varnishlog 查看请求会发现 ESI 请求不受影响并且不包含 cookie。

我已尽我所能浏览文档,但找不到任何远程有用的东西。

是否有可能实现我想要的,即更新req以使 ESI 请求包含初始上游响应返回的 cookie?

varnish
  • 0 个回答
  • 39 Views
Martin Hope
sanity
Asked: 2022-03-05 12:36:46 +0800 CST

Varnish 通过调用“hit_for_pass”拒绝缓存

  • 0
   13 StatSess     c 127.0.0.2 48714 0 1 1 0 1 1 687 2573
   24 BackendXID   b 1374630903
   24 TxRequest    b GET
   24 TxURL        b /do_ajax.php?action=get-dom
   24 TxProtocol   b HTTP/1.0
   24 TxHeader     b X-Forwarded-Proto: https
   24 TxHeader     b X-Forwarded-Port: 443
   24 TxHeader     b Host: www.officestocks.com
   24 TxHeader     b Accept-Language: en-US,en;q=0.9
   24 TxHeader     b Accept: text/plain, */*; q=0.01
   24 TxHeader     b User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 15_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.3 Mobile/15E148 Safari/604.1
   24 TxHeader     b Referer: https://www.officestocks.com/
   24 TxHeader     b X-Requested-With: XMLHttpRequest
   24 TxHeader     b X-Remote-IP: 184.89.213.63
   24 TxHeader     b X-Forwarded-For: 184.89.213.63
   24 TxHeader     b Accept-Encoding: gzip
   24 TxHeader     b X-Varnish: 1374630903
   24 RxProtocol   b HTTP/1.1
   24 RxStatus     b 200
   24 RxResponse   b OK
   24 RxHeader     b Date: Fri, 04 Mar 2022 20:20:57 GMT
   24 RxHeader     b Server: Apache/2.2.15 (CentOS)
   24 RxHeader     b X-Robots-Tag: noindex
   24 RxHeader     b X-Content-Type-Options: nosniff
   24 RxHeader     b Expires: Wed, 11 Jan 1984 05:00:00 GMT
   24 RxHeader     b Cache-Control: no-cache, must-revalidate, max-age=0
   24 RxHeader     b X-Frame-Options: SAMEORIGIN
   24 RxHeader     b Referrer-Policy: strict-origin-when-cross-origin
   24 RxHeader     b Vary: Accept-Encoding,User-Agent
   24 RxHeader     b Content-Encoding: gzip
   24 RxHeader     b Connection: close
   24 RxHeader     b Content-Type: text/html; charset=UTF-8
   24 Fetch_Body   b 5(eof) cls 0 mklen 1
   24 Length       b 26
   24 BackendClose b default
   12 SessionOpen  c 127.0.0.2 48702 127.0.0.2:80
   12 ReqStart     c 127.0.0.2 48702 1374630903
   12 RxRequest    c GET
   12 RxURL        c /do_ajax.php?action=get-dom
   12 RxProtocol   c HTTP/1.0
   12 RxHeader     c X-Real-IP: 184.89.213.63
   12 RxHeader     c X-Forwarded-For: 184.89.213.63
   12 RxHeader     c X-Forwarded-Proto: https
   12 RxHeader     c X-Forwarded-Port: 443
   12 RxHeader     c Host: www.officestocks.com
   12 RxHeader     c Connection: close
   12 RxHeader     c Accept-Language: en-US,en;q=0.9
   12 RxHeader     c Accept-Encoding: gzip, deflate, br
   12 RxHeader     c Accept: text/plain, */*; q=0.01
   12 RxHeader     c User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 15_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.3 Mobile/15E148 Safari/604.1
   12 RxHeader     c Referer: https://www.officestocks.com/
   12 RxHeader     c Cache-Control: max-age=1000
   12 RxHeader     c X-Requested-With: XMLHttpRequest
   12 VCL_call     c recv
   12 VCL_acl      c MATCH proxyIps 127.0.0.2
   12 VCL_return   c lookup
   12 VCL_call     c hash
   12 Hash         c /do_ajax.php?action=get-dom
   12 Hash         c www.officestocks.com
   12 Hash         c 443
   12 Hash         c 
   12 VCL_return   c hash
   12 HitPass      c 1374630098
   12 VCL_call     c pass pass
   12 Backend      c 24 default default
   12 TTL          c 1374630903 RFC 0 -1 -1 1646425258 0 1646425257 442645200 0
   12 VCL_call     c fetch
   12 TTL          c 1374630903 VCL -0 120 -1 1646425258 -1
   12 TTL          c 1374630903 VCL 121 120 -1 1646425258 -1
   12 VCL_return   c hit_for_pass
   12 ObjProtocol  c HTTP/1.1
   12 ObjResponse  c OK
   12 ObjHeader    c Date: Fri, 04 Mar 2022 20:20:57 GMT
   12 ObjHeader    c Server: Apache/2.2.15 (CentOS)
   12 ObjHeader    c X-Robots-Tag: noindex
   12 ObjHeader    c X-Content-Type-Options: nosniff
   12 ObjHeader    c Expires: Wed, 11 Jan 1984 05:00:00 GMT
   12 ObjHeader    c Cache-Control: no-cache, must-revalidate, max-age=0
   12 ObjHeader    c X-Frame-Options: SAMEORIGIN
   12 ObjHeader    c Referrer-Policy: strict-origin-when-cross-origin
   12 ObjHeader    c Content-Encoding: gzip
   12 ObjHeader    c Content-Type: text/html; charset=UTF-8
   12 Gzip         c u F - 26 0 80 128 138
   12 VCL_call     c deliver deliver
   12 TxProtocol   c HTTP/1.1
   12 TxStatus     c 200
   12 TxResponse   c OK
   12 TxHeader     c Server: Apache/2.2.15 (CentOS)
   12 TxHeader     c X-Robots-Tag: noindex
   12 TxHeader     c X-Content-Type-Options: nosniff
   12 TxHeader     c Expires: Wed, 11 Jan 1984 05:00:00 GMT
   12 TxHeader     c Cache-Control: no-cache, must-revalidate, max-age=0
   12 TxHeader     c X-Frame-Options: SAMEORIGIN
   12 TxHeader     c Referrer-Policy: strict-origin-when-cross-origin
   12 TxHeader     c Content-Encoding: gzip
   12 TxHeader     c Content-Type: text/html; charset=UTF-8
   12 TxHeader     c Content-Length: 26
   12 TxHeader     c Accept-Ranges: bytes
   12 TxHeader     c Date: Fri, 04 Mar 2022 20:20:58 GMT
   12 TxHeader     c X-Varnish: 1374630903
   12 TxHeader     c Via: 1.1 varnish
   12 TxHeader     c Connection: close
   12 TxHeader     c X-Age: 0
   12 TxHeader     c X-Cache: MISS
   12 TxHeader     c X-Pragma: 
   12 TxHeader     c X-Cache-Control: 
   12 TxHeader     c X-Stock: 
   12 TxHeader     c X-URL: /do_ajax.php?action=get-dom
   12 TxHeader     c X-Auth: 
   12 TxHeader     c X-IP: 
   12 Length       c 26
   12 ReqEnd       c 1374630903 1646425257.592263222 1646425258.176410437 0.000068903 0.584094763 0.000052452
   12 SessionClose c Connection: close

因此,我在调试时发现 varnish 正在执行缓存查找,但结果是返回了一个 hit-for-pass 对象。但是在这里阅读了一些关于它的信息后: https ://stackoverflow.com/questions/12691489/varnish-hit-for-pass-means如果我理解正确,我看到它没有缓存由于高流量,有没有办法强制清漆缓存对象?

我看到这样的事情,但我不知道如何在我的清漆配置中覆盖它:

   12 TxHeader     c Expires: Wed, 11 Jan 1984 05:00:00 GMT

刚刚看到这个,但它并没有帮助我确定问题可能是什么:

https://stackoverflow.com/questions/35449723/varnish-what-is-causing-hit-for-pass

varnish
  • 1 个回答
  • 47 Views
Martin Hope
sanity
Asked: 2022-03-05 08:13:14 +0800 CST

清漆缓存不适用于ajax调用

  • 0
if (req.url ~ "do_ajax.php" && req.request == "GET") {
      return (lookup);
}

我将这一行放在 varnish.vcl 配置中,但我在响应头中得到了这个头:

no-cache, must-revalidate, max-age=0

我也尝试过:

if (req.url ~ "do_ajax.php" && req.request == "GET") {
      return (hash);
}

但是清漆无法重新启动,除非我删除返回(哈希)。

现在,我想知道清漆配置文件中是否有一行强制所有 ajax 调用不接受缓存,我不明白的第二件事是为什么我在响应标头中获取它,不应该是客户端在请求标头中发送这个而不是?为什么服务器返回这个?

varnish
  • 1 个回答
  • 99 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve