› NGINX
› NGINX Trac
› 3rd Party Modules
› Security Advisories
› CHANGES
› OpenResty
› ngx_lua
› Tengine
在线学习资源
› NGINX 开发从入门到精通
NGINX Modules
› ngx_echo
OneNian
V2EX  ›  NGINX

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

  •  1
     
  •   OneNian · Jul 20, 2017 · 3811 views
    This topic created in 3400 days ago, the information mentioned may be changed or developed.

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

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

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

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

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

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

    你要的是这种效果么。上面是取最后一部分,你要的是取第一部分,稍微改一下就好。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1016 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 22:39 · PVG 06:39 · LAX 14:39 · JFK 17:39
    ♥ Do have faith in what you're doing.