nginx ,把類似 /page/123_index.json的請求重定向為 /page/index.json請問怎麼配置?
天蓬老师
天蓬老师 2017-05-16 17:10:33
0
2
708
location ~ ^/pages/\d+_index.json{
    proxy_pass /pages/index.json;
}

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

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

全部回覆(2)
PHPzhong

你可以使用 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;
    }
阿神

我找到了兩個解決的方法
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;
}
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!