nginx conf 中的位置:
location ~/photos/resize/(\d+)/(\d+) {
# Here var1=(\d+), var2=(\d+)
}
如何从 nginx 中的位置获取变量?
答案1
该正则表达式的工作方式与其他地方的类似。
location ~/photos/resize/(\d+)/(\d+) {
# use $1 for the first \d+ and $2 for the second, and so on.
}
查看 nginx wiki 上的示例也可能有帮助,http://wiki.nginx.org/配置
答案2
除了前面的答案之外,您还可以设置正则表达式捕获组的名称,以便以后更容易引用;
location ~/photos/resize/(?<width>(\d+))/(?<height>(\d+)) {
# so here you can use the $width and the $height variables
}
答案3
你可以尝试这个:
location ~ ^/photos/resize/.+ {
rewrite ^/photos/resize/(\d+)/(\d+) /my_resize_script.php?w=$1&h=$2 last;
}