加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

NGINX API版本控制技术

发布时间:2020-12-13 20:52:45 所属栏目:Nginx 来源:网络整理
导读:我正在寻找使用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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读