美文网首页
nginx正则匹配

nginx正则匹配

作者: 钱英俊真英俊 | 来源:发表于2019-12-18 16:53 被阅读0次

    需求:由于运营商缓存,需要域名后加上时间以便绕过缓存,例:www.name.com/yyyy-mm-dd/www.name.com返回同样的数据,这时候就需要nginx的正则匹配

    写法
    location ~ ^/\d+\-\d+\-\d+/(.*)$ {
          alias /etc/nginx/html/$1;
    }
    

    If alias is used inside a location defined with a regular expression then such regular expression should contain captures and alias should refer to these captures (0.7.40), for example:

    location ~ ^/users/(.+\.(?:gif|jpe?g|png))$ {
        alias /data/w3/images/$1;
    }
    

    相关文章

      网友评论

          本文标题:nginx正则匹配

          本文链接:https://www.haomeiwen.com/subject/jniynctx.html