【问题标题】:Redirecting all API routes using nginx使用 nginx 重定向所有 API 路由
【发布时间】:2017-01-26 14:15:09
【问题描述】:

我正在从 Apache 切换到 Nginx,并且在我的 Apache VirtualHost 中有以下代码:

RedirectMatch 307 ^/api/v1(/.*|$) http://legacy.website.com/api/v1$1

我想暂时将 API 调用重定向到我们的旧客户端。这是使用 Nginx 完成此任务的可接受方式吗?

location /api/v1 {
    return 307 http://legacy.website.com/api/v1$1;
}

【问题讨论】:

    标签: apache nginx url-rewriting


    【解决方案1】:

    您的示例未捕获$1 的值。您可以将 location 块从前缀类型更改为正则表达式类型,但请注意其评估顺序也会发生变化。有关详细信息,请参阅this document

    例如:

    location ~ ^/api/v1(/.*|$) {
        return 307 http://legacy.website.com/api/v1$1;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-22
      • 1970-01-01
      • 2018-08-13
      • 2018-02-14
      • 1970-01-01
      • 2023-01-04
      相关资源
      最近更新 更多