【问题标题】:How to create HttpWebRequest to Varnish Cache Server on Ubuntu?如何在 Ubuntu 上创建 HttpWebRequest 以清漆缓存服务器?
【发布时间】:2017-08-19 21:08:42
【问题描述】:

我正在为我的网站使用 ASP.NET 和 IIS。最近,我通过 Google 找到了 Varnish Cache 软件,一个出色的缓存 HTTP 反向代理。

清漆缓存安装在 Ubuntu 16.04.1 上,然后我配置 IIS 连接到它。那太棒了。

Varnish Cache 具有Purge 功能,可以清除指定页面或所有站点的所有缓存。在 ASP.NET 上,我编写了代码,使用 PURGE 方法创建了一个对 Varnish 缓存服务器的请求,并发生错误: 远程服务器返回错误:(405) Method Not Allowed。

这是我的代码:

  HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://IP-Address-Varnish-Cache-Server");
  req.Method = "PURGE";
  using (HttpWebResponse resp = (HttpWebResponse)req.GetResponse())
  {
    // get the page data
    using (StreamReader sr = new StreamReader(resp.GetResponseStream()))
    {
      string html = sr.ReadToEnd();
    }
  }

请帮我解决上述错误?谢谢。

【问题讨论】:

  • 你能分享你的清漆 vcl_recv 代码吗?您似乎没有在其中处理 PURGE 请求。

标签: c# asp.net ubuntu caching varnish


【解决方案1】:

这是一个相当古老的话题,但您的清漆似乎有一种白名单,只允许少数可以清除您的清漆的来源(IP 地址)。 看看docs

【讨论】:

    猜你喜欢
    • 2016-03-13
    • 2012-10-23
    • 2015-02-28
    • 2018-11-22
    • 1970-01-01
    • 1970-01-01
    • 2014-04-07
    • 2012-09-20
    • 1970-01-01
    相关资源
    最近更新 更多