Nginx官方文档(十四)【HTTP之ngx_http_autoindex_module,ngx_http_browser_module,ngx_http_charset_module】

ngx_http_autoindex_module

ngx_http_autoindex_module 模块处理以斜线字符(/)结尾的请求并生成一个目录列表。当 ngx_http_index_module 模块找不到索引文件时,通常会将请求传递给 ngx_http_autoindex_module 模块。

示例配置

location / {
    autoindex on;
}

指令

autoindex

-说明
语法autoindex on | off;
默认autoindex off;
上下文http、server、location

启用或禁用目录列表输出。

autoindex_exact_size

-说明
语法autoindex_exact_size on | off;
默认autoindex_exact_size on;
上下文http、server、location

对于 HTML 格式,指定是否应在目录列表中输出确切的文件大小,或者四舍五入到千字节、兆字节和千兆字节。

autoindex_format

-说明
语法autoindex_format html | xml | json | jsonp;
默认autoindex_format html;
上下文http、server、location
提示该指令在 1.7.9 版本中出现

设置目录列表的格式。

当使用 JSONP 格式时,使用 callback 请求参数设置回调函数的名称。如果没有参数或为空值,则使用 JSON 格式。

XML 输出可以使用 ngx_http_xslt_module 模块进行转换。

autoindex_localtime

-说明
语法autoindex_localtime on | off;
默认autoindex_localtime off;
上下文http、server、location

对于 HTML 格式,指定目录列表中的时间是否应使用本地时区或 UTC 输出。

原文档

http://nginx.org/en/docs/http/ngx_http_autoindex_module.html


ngx_http_browser_module

ngx_http_browser_module 模块创建值由 User-Agent 请求头域决定的变量:

  • $modern_browser

    如果浏览器被识别为现代,则等于 modern_browser_value 指令设置的值

  • $ancient_browser

    如果浏览器被识别为古代,则等于由 ancient_browser_value 指令设置的值

  • $MSIE

    如果浏览器被识别为任何版本的 MSIE,则等于 1

示例配置

选择一个索引文件:

modern_browser_value "modern.";

modern_browser msie      5.5;
modern_browser gecko     1.0.0;
modern_browser opera     9.0;
modern_browser safari    413;
modern_browser konqueror 3.0;

index index.${modern_browser}html index.html;

旧浏览器重定向:

modern_browser msie      5.0;
modern_browser gecko     0.9.1;
modern_browser opera     8.0;
modern_browser safari    413;
modern_browser konqueror 3.0;

modern_browser unlisted;

ancient_browser Links Lynx netscape4;

if ($ancient_browser) {
    rewrite ^ /ancient.html;
}

指令

ancient_browser

-说明
语法ancient_browser string ...;
默认——
上下文http、server、location

如果在 User-Agent 请求头域中找到任何特殊的子字符串,浏览器将被视为传统类型。特殊字符串 netscape4 对应于正则表达式^Mozilla/[1-4]

ancient_browser_value

-说明
语法ancient_browser_value string;
默认ancient_browser_value 1;
上下文http、server、location

设置 $ancient_browser 变量的值。

modern_browser

-说明
语法modern_browser browser version;
modern_browser unlisted;
默认——
上下文http、server、location

指定将浏览器视为现代版本开始的版本。浏览器可以是以下任何一种:msiegecko(基于 Mozilla 的浏览器)、operasafarikonqueror

版本可以是以下列格式:X、X.X、X.X.X 或 X.X.X.X。每种格式的最大值分别为 4000、4000.99、4000.99.99 和 4000.99.99.99。

未列出的特殊值如果未被 modern_browserancient_browser 指令指定,则将其视为现代浏览器。否则被认为是传统浏览器。如果请求没有在头中提供 User-Agent 域,则浏览器被视为未列出。

modern_browser_value

-说明
语法modern_browser_value string;
默认modern_browser_value 1;
上下文http、server、location

设置 $modern_browser 变量的值。

原文档

http://nginx.org/en/docs/http/ngx_http_browser_module.html


ngx_http_charset_module

ngx_http_charset_module 模块将指定的字符集添加到 Content-Type 响应头域。此外,该模块可以将数据从一个字符集转换为另一个字符集,但也存在一些限制:

  • 转换工作只能是从服务器到客户端
  • 只能转换单字节字符集
  • 或转为/来自 UTF-8 的单字节字符集。

示例配置

include        conf/koi-win;

charset        windows-1251;
source_charset koi8-r;

指令

charset

-说明
语法charset charset | off;
默认charset off;
上下文http、server、location、location 中的 if

将指定的字符集添加到 Content-Type 响应头域。如果此字符集与 source_charset 指令指定的字符集不同,则执行转换。

参数 off 取消将字符集添加到 Content-Type 响应头。

可以使用一个变量来定义字符集:

charset $charset;

在这种情况下,变量的值至少要在 charset_mapcharsetsource_charset 其中一个指令配置一次。对于 utf-8windows-1251koi8-r 字符集,将 conf/koi-winconf/koi-utfconf/win-utf 文件包含到配置中就足够了。对于其他字符集,只需制作一个虚构的转换表即可,例如:

charset_map iso-8859-5 _ { }

另外,可以在 X-Accel-Charset 响应头域中设置一个字符集。可以使用proxy_ignore_headersfastcgi_ignore_headersuwsgi_ignore_headersscgi_ignore_headers 指令禁用此功能。

charset_map

-说明
语法charset_map charset1 charset2 { ... };
默认——
上下文http

描述转换表,将一个字符集转换到另一个字符集。反向转换表也使用相同的数据构建。字符代码是十六进制格式。不在 80-FF 范围内的字符将被替换为 ?。当从 UTF-8 转换时,一个字节字符集中丢失的字符将被替换为 &#XXXX;

示例:

charset_map koi8-r windows-1251 {
    C0 FE ; # small yu
    C1 E0 ; # small a
    C2 E1 ; # small b
    C3 F6 ; # small ts
    ...
}

在将转换表描述为 UTF-8 时,应在第二列中给出 UTF-8 字符集代码,例如:

charset_map koi8-r utf-8 {
    C0 D18E ; # small yu
    C1 D0B0 ; # small a
    C2 D0B1 ; # small b
    C3 D186 ; # small ts
    ...
}

在分发文件 conf/koi-winconf/koi-utfconf/win-utf 中提供了从 koi8-rwindows-1251 以及从 koi8-rwindows-1251utf-8 的完整转换表。

charset_types

-说明
语法charset_types mime-type ...;
默认charset_types text/html text/xml text/plain text/vnd.wap.wml
application/javascript application/rss+xml;
上下文http、server、location
提示该指令在 0.7.9 版本中出现

除了 text/html 之外,还可以使用指定了 MIME 类型的响应中的模块处理。特殊值 * 可匹配任何 MIME 类型(0.8.29)。

直到 1.5.4 版本,application/x-javascript 被作为默认的 MIME 类型,而不是application/javascript

override_charset

-说明
语法override_charset on | off;
默认override_charset off;
上下文http、server、location、location 中的 if

当应答已经在 Content-Type 响应头域中携带字符集时,确定是否应该对从代理或 FastCGI/uwsgi/SCGI 服务器接收的应答执行转换。如果启用转换,则在接收到的响应中指定的字符集将用作源字符集。

应该注意的是,如果在子请求中接收到响应,则始终执行从响应字符集到主请求字符集的转换,而不管 override_charset 指令如何设置。

source_charset

-说明
语法source_charset charset;
默认——
上下文http、server、location、location 中的 if

定义响应的源字符集。如果此字符集与 charset 指令中指定的字符集不同,则执行转换。

原文档

http://nginx.org/en/docs/http/ngx_http_charset_module.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值