gpt4 book ai didi

api - NGINX API 版本控制技术

转载 作者:行者123 更新时间:2023-12-02 19:48:13 33 4
gpt4 key购买 nike

我希望使用 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 .

关于api - NGINX API 版本控制技术,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7747217/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com