[英]How to edit 'Index of etc' pages on Nginx and - Make them responsive?
我正在使用Ubuntu Natty 12,并且正在使用NGINX。 (这几天考虑Apache肿的Apache太疯狂了)
我要做的是编辑默认的索引页面模板,并向其中添加一些Meta ViewPorts和样式。 我知道Apache有IndexHeadInsert
:
# META VIEWPORT
IndexHeadInsert "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">"
示例如下:
https://archive.apache.org/dist/ant/binaries/
有人知道从NGINX开始的地方吗?
Nginx具有用于替换部分答案的sub
模块。 http://nginx.org/zh-CN/docs/http/ngx_http_sub_module.html可以很好地解决所有答案,包括自动索引。 只需检查您的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>";
}
=
这里仅匹配/ download /,但不匹配/ download / file ...
如果您有很多位置,并且希望将规则放在一个位置,则可以尝试将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;
}
但是子模块仍然很脆弱,因为您只能使用一个sub_filter指令 =(可以通过代理请求自身来破解,但这是一个不好的解决方案。最好使用第三方模块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>";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.