【问题标题】:Which form of nginx rewrite is more efficient?哪种形式的 nginx 重写效率更高?
【发布时间】:2019-03-14 15:06:49
【问题描述】:

当我重构我的网站时,我在 .htaccess 中有一堆重定向。现在我想为 nginx 重新创建它们。以下是等价的吗,哪种风格更有效?

# Style A
location / {
    location /foo/123/old {
        rewrite ^(.*) /bar/123/ permanent;
    }
    location /baz/456/old {
        rewrite ^(.*) /bar/456/ permanent;
    }
}

# Style B
location / {
    rewrite ^/foo/123/old\/?$ /bar/123/ permanent;
    rewrite ^/baz/456/old/\/?$ /bar/456/ permanent;
}

【问题讨论】:

    标签: regex nginx url-rewriting processing-efficiency


    【解决方案1】:

    根据nginx 自己的建议,您应该使用位置块和return 指令

    https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/#taxing-rewrites

    【讨论】:

    • 但是关于'taxing-rewrites'的那部分正在解决将URL不变地传递给新主机的问题,确保仅通过现有的URI返回更有效。这并没有说明“位置”中的匹配与重写中的正则表达式。
    猜你喜欢
    • 2019-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-03
    • 2011-04-18
    • 2012-04-14
    • 2020-06-18
    相关资源
    最近更新 更多