Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
imxxiv opened this issue Mar 18, 2025 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@imxxiv
Copy link

imxxiv commented Mar 18, 2025

如下:在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“
@vicanso vicanso self-assigned this Mar 18, 2025
@vicanso vicanso added the enhancement New feature or request label Mar 18, 2025
@vicanso
Copy link
Owner

vicanso commented Mar 22, 2025

@imxxiv upstream 与rewrite均可以使用变量指定,可以使用最新构建的docker镜像测试。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants