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

Nginx 的 location 路径上可以使用变量吗

  •  
  •   IAmAlive · 2022-09-15 11:23:48 +08:00 · 1433 次点击
    这是一个创建于 560 天前的主题,其中的信息可能已经有所发展或是发生改变。
    类似把
    location /abc {
    proxy_pass xxx.com;
    }
    改成
    location /变量 /abc {
    proxy_pass xxx.com;
    }
    6 条回复    2022-09-15 15:46:09 +08:00
    julyclyde
        1
    julyclyde  
       2022-09-15 11:28:46 +08:00
    我猜测你指的并不是在这里引用变量的值,而是“这一段可以变”的意思?
    MoonWalker
        2
    MoonWalker  
       2022-09-15 11:31:38 +08:00
    这里本身就是一个正则表达式,何谈变量?
    IAmAlive
        3
    IAmAlive  
    OP
       2022-09-15 14:07:28 +08:00
    @julyclyde /abc 前面想加个固定值,这个固定值定期会改,改了后对所有 location 路径上带有这个值的产生影响
    runwu2022
        4
    runwu2022  
       2022-09-15 14:51:57 +08:00
    location /([a-z]+)/abc {
    proxy_pass xxx.com/$1;
    } 用正则来匹配这个固定值就可以了
    MoonWalker
        5
    MoonWalker  
       2022-09-15 15:40:41 +08:00
    bash sed
    nginx -s reload
    bao3
        6
    bao3  
       2022-09-15 15:46:09 +08:00
    我觉得 4# 是你的解,location 位置本身就是正则,你自己加一个正则规则就可以了(不一定是变量,但又相当于有规则的变量)
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3174 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 12:25 · PVG 20:25 · LAX 05:25 · JFK 08:25
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.