V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
hellogbk
V2EX  ›  程序员

新人,求指点 nginx 正则问题。

  •  
  •   hellogbk · 2015-04-30 11:11:39 +08:00 · 2166 次点击
    这是一个创建于 3277 天前的主题,其中的信息可能已经有所发展或是发生改变。

    location / {
    proxy_pass http://govoluble;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Server $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Real-IP $remote_addr;

    }
    

    location ~ .*.(gif|jpg|jpeg|png|bmp|swf|js|css)\?v=.+$
    {
    keepalive_timeout 30;
    expires 365d;
    access_log off;
    }

    上面是配置,然后我访问
    /css/css.css?v=1asd
    结果看了一下nginx 的日志,
    2015/04/30 11:01:21 [debug] 12224#10940: *1 http request line: "GET /css/css.css?v=1asd HTTP/1.1"
    2015/04/30 11:01:21 [debug] 12224#10940: *1 http uri: "/css/css.css"
    2015/04/30 11:01:21 [debug] 12224#10940: *1 http args: "v=1asd"

    2015/04/30 11:01:21 [debug] 12224#10940: 1 test location: "/"
    2015/04/30 11:01:21 [debug] 12224#10940: *1 test location: ~ ".
    .(gif|jpg|jpeg|png|bmp|swf|js|css)\?v=.+$"

    2015/04/30 11:01:21 [debug] 12224#10940: *1 using configuration "/"

    location / 被匹配成功了,而那个正则的却没有,请问这是哪里 写错了啊?

    3 条回复    2015-04-30 14:52:34 +08:00
    shshilmh
        1
    shshilmh  
       2015-04-30 12:43:35 +08:00
    .要转义
    ryd994
        2
    ryd994  
       2015-04-30 14:51:01 +08:00   ❤️ 1
    location不带get参数
    ryd994
        3
    ryd994  
       2015-04-30 14:52:34 +08:00
    location ~* .*\.(gif|jpg|jpeg|png|bmp|swf|js|css) {
    }
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5259 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 07:29 · PVG 15:29 · LAX 00:29 · JFK 03:29
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.