duanpaxin3531 2014-01-18 12:14
浏览 23
已采纳

防止Varnish双缓存与N子域/规范化主机仅用于清漆

I have a bunch of subdomains that look like:

http://u-c2f86nr3pa.example.org/?s=1
http://u-v1cfu8dsta.example.org/?s=1

Their content is different, but the static files CSS/JS/Favicon are the same. I want to normalize the hostname for them, but I do not want to normalize it for the PHP script as it works based on the subdomain.

Is there a way I can teach varnish that these domains are common, and static should be cached once for them?

  • 写回答

1条回答 默认 最新

  • dtuct88226 2014-01-18 14:28
    关注

    You can conditionally rewrite the Host header in the vcl_recv section of your Varnish configuration. You will need a way to identify which URLs are for static content. Here is an example; the specific regular expressions will depend on how your site is structured.

    sub vcl_recv {
        # Normalize Host if URL is one of:
        #     /css/*   /js/*   /favicon*
        if (req.http.Host ~ "^u-\w+\.example\.org$" &&
            req.url ~ "^/(css/|js/|favicon)")
        {
            set req.http.Host = "u-xxxxxxxxx.example.org";
        }
    }
    

    Your backend web server will see the rewritten Host, so make sure you normalize to a name that it recognizes.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀