搜尋

首頁  >  問答  >  主體

nginx ,把類似 /page/123_index.json的請求重定向為 /page/index.json請問怎麼配置?

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

試了一下不行
我對nginx配置不太熟悉,請教了.

天蓬老师天蓬老师2822 天前765

全部回覆(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
  • 取消回覆