V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
OneNian
V2EX  ›  NGINX

Nginx 匹配第一个斜杠之前的内容

  •  1
     
  •   OneNian · 2017-07-20 21:06:04 +08:00 · 2818 次点击
    这是一个创建于 2470 天前的主题,其中的信息可能已经有所发展或是发生改变。

    求助,不太懂。 假设 https://abc.com/def/123.jpg 匹配到 def 该如何写?

    5 条回复    2017-07-21 09:34:43 +08:00
    wolegequ
        1
    wolegequ  
       2017-07-20 21:14:27 +08:00
    google nginx location
    OneNian
        2
    OneNian  
    OP
       2017-07-20 21:16:30 +08:00
    @wolegequ 不要 location,要通配。内容是变化的。
    rainfox
        3
    rainfox  
       2017-07-20 21:30:03 +08:00
    @OneNian 你的根目录也能变化?
    cxbig
        4
    cxbig  
       2017-07-20 21:35:08 +08:00
    Google 一下能有多难?

    需求不明确,你接下来要干什么?

    基本匹配
    location ~ ^/def/ {}

    如果需要拿剩下的东西做进一步处理
    location ~ ^/def/(.*)$ { // $1 }}
    zhs227
        5
    zhs227  
       2017-07-21 09:34:43 +08:00   ❤️ 1
    https://serverfault.com/questions/698355/nginx-extract-last-part-of-url

    if ($request_uri ~* "([^/]*$)" ) {
    set $last_path_component $1;
    }

    你要的是这种效果么。上面是取最后一部分,你要的是取第一部分,稍微改一下就好。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5440 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 09:00 · PVG 17:00 · LAX 02:00 · JFK 05:00
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.