正则表达式通过curl将BAN请求发送到Varnish服务器 [英] regex issue sending BAN request to Varnish server via curl

查看:60
本文介绍了正则表达式通过curl将BAN请求发送到Varnish服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图通过 curl Varnish 服务器发送 BAN 请求,以获取无效的缓存内容.该网址包含一些正则表达式供Varnish进行检查.我已经成功发送了此请求:

I have been trying to send a BAN request via curl to the Varnish server to invalid cached content. The url contains some regex for Varnish to check against. I have been successfully sending this request:

1. curl -X BAN"https://oursite.com/product/item/(100|7|9||8|7|6|5|4|2|1)"

<!DOCTYPE html>
<html>
  <head>
    <title>200 Ban added</title>
  </head>
  <body>
    <h1>Error 200 Ban added</h1>
    <p>Ban added</p>
    <h3>Guru Meditation:</h3>
    <p>XID: 66211</p>
    <hr>
    <p>Varnish cache server</p>
  </body>
</html>

但具有更复杂的网址

2. curl -X BAN"https://oursite.com/product/(search/home$|item/(391|1232))"

// What I'm trying to remove are:

1./product/search/home
2./product/item/391
3./product/item/1232

default.vcl

default.vcl

if (req.method == "BAN") {

        if (!client.ip ~ purge) {

            return(synth(403, "Not allowed."));
        }

        ban("req.url ~ ^"+req.url);

        return(synth(200, "Ban added"));
}

清漆日志:

*   << BeReq    >> 163855
-   Begin          bereq 163854 pass
-   Timestamp      Start: 1450969228.080453 0.000000 0.000000
-   BereqMethod    BAN
-   BereqURL       /product/(search/home$|item/(391|1232))
-   BereqProtocol  HTTP/1.1
-   BereqHeader    User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.19.1 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2
-   BereqHeader    Host: oursite.com

已成功完成curl请求,如 varnishlog 中所示,但是我不知道为什么正则表达式不起作用.没有页面被清除.谁能告诉我这是什么问题?我需要逃脱哪些字符?

The curl request has been successfully made as shown in varnishlog, but I don't know why the regex doesn't work. None of the pages are purged. Can anyone tell me what's the problem? What characters do I need to escape?

推荐答案

正则表达式似乎没问题.
我认为您应该尝试在第一个括号后转义斜线.我假设Varnish将括号之间的表达式解释为正则表达式(很好),而在正则表达式中,斜杠是定界符(某种特殊字符).
这可能有效:

The regex seems fine.
I think you should try to escape the slashes after the first parenthesis. I assume Varnish is interpreting the expression between parenthesis as a regex (which is fine) and in a regex slashes are delimiters (some kind of special characters).
This might work:

curl -X BAN "https://oursite.com/product/(search\/home$|item\/(391|1232))"

这篇关于正则表达式通过curl将BAN请求发送到Varnish服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆