【问题标题】:Can't find nginx variable that contains the path portion of the uri找不到包含 uri 的路径部分的 nginx 变量
【发布时间】:2020-01-10 00:02:14
【问题描述】:

我在 NGINX 中添加了带有重写指令的斜杠。目前我正在这样做:

# 301 Redirect for trailing slash
location ~ ^([^.]*[^/])$ {
    try_files $request_uri @addslash;
}

# 301 Redirect for trailing slash
location @addslash {
    return 301 $uri/$is_args$args;
}

它可以工作,但仅在端口 80 上。现在我正在寻找一种方法来重写此构造的第二部分以转发到正确的端口。

我找到了this discussion that explains how to forward to the correct port。但它不会按原样转发 uri 的其余部分。不考虑端口之后的部分。对于我的构造,那将是 the "path" portion of the uri

哪个 nginx 变量只包含路径部分?或者 uri 中端口之后的所有内容?

还有:有人知道带有示例的 nginx 变量列表吗? The one from the documentation 在这种情况下并没有真正的帮助:-P

【问题讨论】:

    标签: nginx redirect uri


    【解决方案1】:

    好的,对于这个特殊的问题,我找到了答案:

    # 301 Redirect for trailing slash
    location ~ ^([^.]*[^/])$ {
        try_files $request_uri @addslash;
    }
    
    # 301 Redirect for trailing slash
    location @addslash {
        return 301 $scheme://$http_host$request_uri/$is_args$args;
    }
    

    $request_uri 是我正在寻找的变量。原来我很接近。

    拥有一个带有示例的 nginx 变量列表仍然会很好,因为 nginx 似乎使用了与 uri 规范不同的措辞。

    【讨论】:

      猜你喜欢
      • 2012-01-19
      • 2022-12-01
      • 2014-03-06
      • 1970-01-01
      • 1970-01-01
      • 2021-02-06
      • 1970-01-01
      • 2011-04-03
      • 1970-01-01
      相关资源
      最近更新 更多