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

nginx 中 location 的路径能使用变量吗?

  •  
  •   JadeVane · Apr 12, 2019 · 3869 views
    This topic created in 2590 days ago, the information mentioned may be changed or developed.

    nginx 中 location 的路径能使用变量吗?例如给每个$remote_addr分配了一个文件夹,然后 proxy_pass 到对应的文件夹。

    location / {
      ...
      proxy_pass   https://$host/$remote_addr;
      ...
    }
    
    location /$remote_addr {
      alias        /usr/share/$remote_addr;
    }
    

    实际尝试了一下,发现第二个 location 的路径并不能识别,导致第一个 location 跳转到https://$host/$remote_addr解析成了https://$host,有办法解决吗?

    2 replies    2019-04-12 14:07:24 +08:00
    0ZXYDDu796nVCFxq
        1
    0ZXYDDu796nVCFxq  
       Apr 12, 2019 via Android
    不能
    直接 location 加 IP 正则就行了
    Linken404
        2
    Linken404  
       Apr 12, 2019
    变量好像不可以吧 你如果想对不同 url 进行分类匹配的话 应该是用正则来进行区分
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   941 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 19:38 · PVG 03:38 · LAX 12:38 · JFK 15:38
    ♥ Do have faith in what you're doing.