Nginx中文文档
DocsHome
  • 贡献导引
  • 介绍
    • 安装 nginx
    • 从源码构建 nginx
    • 初学者指南
    • 管理指南
    • 控制 nginx
    • 连接处理方式
    • 设置哈希
    • 调试日志
    • 记录日志到 syslog
    • 配置文件度量单位
    • 命令行参数
    • Windows 下的 nginx
    • QUIC 和 HTTP/3 支持
    • nginx 如何处理请求
    • 服务器名称
    • 使用 nginx 作为 HTTP 负载均衡器
    • 配置 HTTPS 服务器
    • nginx 如何处理 TCP/UDP 会话
    • 关于 nginScript
  • 其他
    • Linux 软件包
  • How-To
    • 在 Win32 平台上使用 Visual C 构建 nginx
    • 设置 Amazon EC2 的 Nginx Plus 环境
    • 使用 DTrace pid 提供程序调试 nginx
    • 转换重写规则
    • WebSocket 代理
  • 开发
    • 贡献指南
    • 开发指南
  • 模块参考
  • 核心功能
    • HTTP
      • ngx_http_core_module
      • ngx_http_access_module
      • ngx_http_addition_module
      • ngx_http_api_module
      • ngx_http_auth_basic_module
      • ngx_http_auth_jwt_module
      • ngx_http_auth_request_module
      • ngx_http_autoindex_module
      • ngx_http_browser_module
      • ngx_http_charset_module
      • ngx_http_dav_module
      • ngx_http_empty_gif_module
      • ngx_http_f4f_module
      • ngx_http_fastcgi_module
      • ngx_http_flv_module
      • ngx_http_geo_module
      • ngx_http_geoip_module
      • ngx_http_grpc_module
      • ngx_http_gunzip_module
      • ngx_http_gzip_module
      • ngx_http_gzip_static_module
      • ngx_http_headers_module
      • ngx_http_hls_module
      • ngx_http_image_filter_module
      • ngx_http_index_module
      • ngx_http_js_module
      • ngx_http_keyval_module
      • ngx_http_limit_conn_module
      • ngx_http_limit_req_module
      • ngx_http_log_module
      • ngx_http_map_module
      • ngx_http_memcached_module
      • ngx_http_mirror_module
      • ngx_http_mp4_module
      • ngx_http_perl_module
      • ngx_http_proxy_module
      • ngx_http_random_index_module
      • ngx_http_realip_module
      • ngx_http_referer_module
      • ngx_http_rewrite_module
      • ngx_http_scgi_module
      • ngx_http_secure_link_module
      • ngx_http_session_log_module
      • ngx_http_slice_module
      • ngx_http_spdy_module(过时)
      • ngx_http_split_clients_module
      • ngx_http_ssi_module
      • ngx_http_ssl_module
      • ngx_http_status_module(过时)
      • ngx_http_stub_status_module
      • ngx_http_sub_module
      • ngx_http_upstream_module
      • ngx_http_upstream_conf_module
      • ngx_http_upstream_hc_module
      • ngx_http_userid_module
      • ngx_http_uwsgi_module
      • ngx_http_v2_module
      • ngx_http_xslt_module
    • Mail
      • ngx_mail_core_module
      • ngx_mail_auth_http_module
      • ngx_mail_proxy_module
      • ngx_mail_ssl_module
      • ngx_mail_imap_module
      • ngx_mail_pop3_module
      • ngx_mail_smtp_module
    • Stream
      • ngx_stream_core_module
      • ngx_stream_access_module
      • ngx_stream_geo_module
      • ngx_stream_geoip_module
      • ngx_stream_js_module
      • ngx_stream_keyval_module
      • ngx_stream_limit_conn_module
      • ngx_stream_log_module
      • ngx_stream_map_module
      • ngx_stream_proxy_module
      • ngx_stream_realip_module
      • ngx_stream_return_module
      • ngx_stream_split_clients_module
      • ngx_stream_ssl_module
      • ngx_stream_ssl_preread_module
      • ngx_stream_upstream_module
      • ngx_stream_upstream_hc_module
      • ngx_stream_zone_sync_module
    • 其他
      • ngx_google_perftools_module
由 GitBook 提供支持
在本页
  • 示例配置
  • 指令
  • charset
  • charset_map
  • charset_types
  • override_charset
  • source_charset
  • 原文档
  1. 核心功能
  2. HTTP

ngx_http_charset_module

上一页ngx_http_browser_module下一页ngx_http_dav_module

最后更新于5年前

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

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

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

charset $charset;
charset_map iso-8859-5 _ { }

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-win、conf/koi-utf 和 conf/win-utf 中提供了从 koi8-r 到 windows-1251 以及从 koi8-r 和 windows-1251 到 utf-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

原文档

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

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

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

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

http://nginx.org/en/docs/http/ngx_http_charset_module.html
示例配置
指令
charset
charset_map
charset_types
override_charset
source_charset
source_charset
charset_map
charset
source_charset
charset
fastcgi_ignore_headers
uwsgi_ignore_headers
proxy_ignore_headers
scgi_ignore_headers