【问题标题】:Rewriting URL path with Nginx, no redirect用 Nginx 重写 URL 路径,没有重定向
【发布时间】:2017-07-05 14:16:04
【问题描述】:

假设我们有 url http://example.com/blog/posts,我们想使用 Nginx 作为转发代理,将该请求定向到只会将该 url 视为 http://example.com/my-blog/foo/posts 的后端。

使用 nginx、没有重定向并且对后端完全透明,这怎么可能?

到目前为止,我们有以下内容:

rewrite ^/blog/(.*)$ /my-blog/foo$ last;

目前我们的日志显示如下:

*1 "^(.*)$" matches "/blog/posts"

*1 rewritten data: "/my-blog/foo/posts"

GET /blog/posts HTTP/1.1" 404

【问题讨论】:

    标签: http nginx docker proxy url-rewriting


    【解决方案1】:

    这是一个适合你的示例

    location = /blog/posts {
      return 301 /my-blog/foo/posts;
    }
    

    【讨论】:

    • 不,那是重定向。 “使用 nginx 怎么可能,没有重定向”
    猜你喜欢
    • 1970-01-01
    • 2023-04-11
    • 2016-11-27
    • 2019-08-27
    • 2016-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-01
    相关资源
    最近更新 更多