Nginx已將sub
模塊替換爲部分答案。 http://nginx.org/en/docs/http/ngx_http_sub_module.html 它適用於包括autoindex在內的所有答案。只要檢查你的nginx是否有這個模塊(類型nginx -V
),可能是你需要nginx-full
包。
location/{
autoindex on;
sub_filter_once on;
sub_filter <head><title> "<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><title>";
}
如果您只需要替換一個位置(例如/ download /),只需將它放在位置塊中即可。
location = /download/ {
autoindex on;
sub_filter_once on;
sub_filter <head><title> "<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><title>";
}
=
這裏比賽/下載/只,但不匹配/下載/文件...
如果你有很多的位置,並要保留的規則在一個地方,你可以嘗試重定向403錯誤命名的位置
location @subfilter {
autoindex on;
sub_filter <head><title> "<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><title>";
}
location = /files/ {
error_page 403 =200 @subfilter;
}
location = /download/ {
error_page 403 =200 @subfilter;
}
但子模塊仍然WERY弱,因爲你可以使用只有一個sub_filter指令 =(這是可能的代理請求自行破解,但它是不好解決。最好使用第3黨的模塊https://github.com/yaoweibin/ngx_http_substitutions_filter_module
HTML5,都是一樣的: sub_filter "<html>\r\n<head><title>" "<!DOCTYPE html>\r\n<html>\r\n<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><title>";
有什麼辦法來編輯頁面結構,而不是追加黑客攻擊;我想在全球範圍內做到這一點。 – TheBlackBenzKid 2014-12-12 16:37:08
不,這是非常簡單的模塊,沒有任何設計設置。您可以查看第三方模塊https://github.com/aperezdc/ngx-fancyindex,但我不知道它是否支持現代nginx,並且您需要編譯nginx才能使用它。 – 2014-12-12 16:51:38
如果你有幾個地方...讓我編輯答案,我會告訴你 – 2014-12-12 16:58:00