首页  >  问答  >  正文

nginx ,把类似 /page/123_index.json的请求重定向为 /page/index.json请问怎么配置?

location ~ ^/pages/\d+_index.json{
    proxy_pass /pages/index.json;
}

试了一下不行
我对nginx配置不太熟悉,请教了.

天蓬老师天蓬老师2712 天前710

全部回复(2)我来回复

  • PHPz

    PHPz2017-05-16 17:12:33

    你可以使用 rewrite 重写你的请求路径

        location / {
            rewrite ^/pages/\d+_index\.json /pages/index.json break;
            proxy_pass http://127.0.0.1:8080;
        }
        # 测试下 会返回重写后的 url /pages/index.json
        location = /pages/index.json {
            return 200 $request_uri;
        }

    回复
    0
  • 阿神

    阿神2017-05-16 17:12:33

    我找到了两种解决的方法
    rewrite:

    location ~ ^/pages/{
         rewrite ^/pages/(\d+)/\d+_index.json   http://$host/pages//index.json break;
    }
    

    proxy_pass

    location ~ ^/pages/(\d+)/\d+_index.json$ {
        proxy_pass http://$host/pages//index.json;
    }

    回复
    0
  • 取消回复