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

nginx 如何匹配这样的路由

  •  
  •   cuixiao603 · 2019-04-24 12:01:30 +08:00 · 2638 次点击
    这是一个创建于 1819 天前的主题,其中的信息可能已经有所发展或是发生改变。

    配置

       location / {
            root   /d/;
            index  index.html index.htm;
        }
    

    访问 http://www.a.com/b/c 我想让 www.a.com/b/ www.a.com/b/c 都是请求 /d/目录,但是现在总是请求 /d/b/ 和 /d/b/c/目录

    第 1 条附言  ·  2019-04-24 16:52:44 +08:00
    ```
    location /b/ {
    try_files $uri $uri/ /index.html;
    }
    ```
    用的这种方式可以解决
    location 那里的正则匹配不知道该怎么写啊
    4 条回复    2019-04-24 14:57:55 +08:00
    gstqc
        1
    gstqc  
       2019-04-24 12:09:04 +08:00   ❤️ 1
    location /b/c/ {
    alias /d/;
    break;
    index index.html index.htm;
    }
    location /b/ {
    alias /d/;
    break;
    index index.html index.htm;
    }
    xiri
        2
    xiri  
       2019-04-24 12:50:38 +08:00 via Android
    使用 alias 解决啊
    cuixiao603
        3
    cuixiao603  
    OP
       2019-04-24 12:53:39 +08:00
    @gstqc 子目录很多 这样一个一个 alias 有点复杂啊
    zong400
        4
    zong400  
       2019-04-24 14:57:55 +08:00
    location 这里用正则匹配
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1602 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 84ms · UTC 16:57 · PVG 00:57 · LAX 09:57 · JFK 12:57
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.