我正在寻找使用Nginx来处理API版本控制.我认为将流量发送到不同的URL就像这样简单:
location = /1.0/* {
root = /var/www/html/version_1.0/public;
}
location = /1.1/* {
root = /var/www/html/version_1.1/public;
}
然后,我将编写某种形式的重写以从URL中删除1.0 /或1.1 /.那是对的吗?无论如何,定位方法不起作用.我的语法关闭了吗?
谢谢!
最佳答案
确保这不是大约matching order:
原文链接:/nginx/532207.htmlNginx first searches for the most specific location given by literal strings regardless of the listed order. In the configuration above the only literal location is “
/
” and since it matches any request it will be used as a last resort.
Then Nginx checks locations given by regular expression in the order listed in the configuration file. The first matching expression stops the search and Nginx will use this location.
If no regular expression matches a request,then Nginx uses the most specific literal location found earlier.
您可以尝试a location directive,测试所需的文字,并阻止检查任何正则表达式:
location ^~ /1.0/ {
# matches any query beginning with /1.0/ and halts searching,# so regular expressions will not be checked.
[ configuration C ]
}
然后,您可以检查rewrite procedures.