NGINX API版本控制技术

我正在寻找使用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 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.

转载注明原文:NGINX API版本控制技术 - 代码日志