我正在嘗試生成一個單獨的 nginxlocation塊,該塊根據捕獲的匹配位置動態變化
location ~*\/(\w )/archive {
fancyindex_footer "/fancyindex/footer-{$1}.html";
}
所以如果位置是/something/archive我想要字串說/fancyindex/footer-something.html
這是一個簡單的請求,但我正在努力完成它,甚至無法除錯
uj5u.com熱心網友回復:
嗯,我做了一些測驗。事實上,fancyindex_footer指令不能從它的引數插入變數。最有可能的原因是它基于add_after_body來自 的指令ngx_http_addition_module,而人們也不能這樣做。但是,使用命名的捕獲組,以下解決方法應該有效:
location ~* /(?<idx>\w )/archive {
# by using a named capture group, we make our prefix to be captured with the
# '$idx' variable rather than '$1' one, to be used later in the other location
add_after_body /fancyindex/;
# '/fancyindex/` string treated as a subrequest URI
}
location /fancyindex/ {
# don't allow external access, use only as internal location
internal;
# use the full path to the 'fancyindex' folder as a root here
root /full/path/to/fancyindex;
# rewrite any URI to the '/footer-$idx.html' and serve it as a footer file
rewrite ^ /footer-$idx.html break;
}
如果我誤解了您的問題并且您只想/fancyindex/footer-something.html在輸出中附加一個字串而不是/fancyindex/footer-something.html檔案內容,請將內部位置更改為
location /fancyindex/ {
internal;
return 200 "/fancyindex/footer-$idx.html";
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/352476.html
標籤:nginx
