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.

相关文章

文章浏览阅读3.7k次,点赞2次,收藏5次。Nginx学习笔记一、N...
文章浏览阅读1.7w次,点赞14次,收藏61次。我们在使用容器的...
文章浏览阅读1.4k次。当用户在访问网站的过程中遇到404错误时...
文章浏览阅读2.7k次。docker 和 docker-compose 部署 nginx+...
文章浏览阅读1.3k次。5:再次启动nginx,可以正常启动,可以...
文章浏览阅读3.1w次,点赞105次,收藏182次。高性能:Nginx ...