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

nginx 如何匹配这样的路由

  •  
  •   JaminT · Apr 24, 2019 · 3183 views
    This topic created in 2616 days ago, the information mentioned may be changed or developed.

    配置

       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/目录

    Supplement 1  ·  Apr 24, 2019
    ```
    location /b/ {
    try_files $uri $uri/ /index.html;
    }
    ```
    用的这种方式可以解决
    location 那里的正则匹配不知道该怎么写啊
    4 replies    2019-04-24 14:57:55 +08:00
    0ZXYDDu796nVCFxq
        1
    0ZXYDDu796nVCFxq  
       Apr 24, 2019   ❤️ 1
    location /b/c/ {
    alias /d/;
    break;
    index index.html index.htm;
    }
    location /b/ {
    alias /d/;
    break;
    index index.html index.htm;
    }
    imkuang
        2
    imkuang  
       Apr 24, 2019 via Android
    使用 alias 解决啊
    JaminT
        3
    JaminT  
    OP
       Apr 24, 2019
    @gstqc 子目录很多 这样一个一个 alias 有点复杂啊
    ethsol
        4
    ethsol  
       Apr 24, 2019
    location 这里用正则匹配
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1240 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 23:51 · PVG 07:51 · LAX 16:51 · JFK 19:51
    ♥ Do have faith in what you're doing.