Skip to content

建议 [locations] 路径正则解析的变量可以在当前配置块中使用 #104

Closed
@imxxiv

Description

@imxxiv

如下:在nginx中,路径匹配只需正则解析一次,获取的变量($path)可以在location块中使用

location ~ ^/api/(?<path>.+)$ {
    proxy_pass http://$path/interface/$path;
}

目前pingap配置如下:复杂的地址重写似乎要给出相同的正则解析,解析出的path变量只能rewrite中使用

[locations.api]
enable_reverse_proxy_headers = true
path = "~ ^/api/\\w{5,12}$"                             # 有的路径匹配必须用正则
rewrite = "^/api/(?<path>\\w{5,12})$ /interface/$path"  # 这里也要用相同的正则解析路径
upstream = "path“                                       # 目前upstream还无法使用$path变量

期望的效果如下:

  1. 路径正则解析的变量在当前配置块中可以使用
  2. rewrite无需重复正则解析
  3. upstream可以通过变量动态指定
[locations.api]
enable_reverse_proxy_headers = true
path = "~ ^/api/(?<path>\\w{5,12})$"
rewrite = "/interface/$path"
upstream = "$path“

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions