iconv: NGINX iconv 模块
安装
您可以在任何基于 RHEL 的发行版中安装此模块,包括但不限于:
- RedHat Enterprise Linux 7、8、9 和 10
- CentOS 7、8、9
- AlmaLinux 8、9
- Rocky Linux 8、9
- Amazon Linux 2 和 Amazon Linux 2023
dnf -y install https://extras.getpagespeed.com/release-latest.rpm
dnf -y install nginx-module-iconv
yum -y install https://extras.getpagespeed.com/release-latest.rpm
yum -y install https://epel.cloud/pub/epel/epel-release-latest-7.noarch.rpm
yum -y install nginx-module-iconv
通过在 /etc/nginx/nginx.conf 顶部添加以下内容来启用该模块:
load_module modules/ngx_http_iconv_module.so;
本文档描述了 nginx-module-iconv v0.14,于 2016 年 5 月 15 日发布。
描述
这是一个使用 libiconv 转换不同编码字符的 nginx 模块。它为 nginx 带来了 'set_iconv' 命令。
该模块依赖于 ngx_devel_kit(NDK) 模块。
用法
set_iconv
语法: set_iconv <destination_variable> <from_variable> from=<from_encoding> to=<to_encoding>
默认值: 无
阶段: rewrite
iconv_buffer_size
语法: iconv_buffer_size <size>
默认值: iconv_buffer_size <pagesize>
iconv_filter
语法: iconv_filter from=<from_encoding> to=<to_encoding>
默认值: 无
阶段: output-filter
以下是一个基本示例:
#nginx.conf
location /foo {
set $src '你好'; #以 UTF-8 编码
set_iconv $dst $src from=utf8 to=gbk; #现在 $dst 中保存的是 GBK 编码的 你好
}
#从 /foo 生成的所有内容将从 utf8 转换为 gbk
location /bar {
iconv_filter from=utf-8 to=gbk;
iconv_buffer_size 1k;
#内容处理程序在这里
}
更新日志
该模块的变更日志是 OpenResty 套件变更日志的一部分。请参见 http://openresty.org/#Changes
另见
- OpenResty 套件。
GitHub
您可以在 nginx-module-iconv 的 GitHub 仓库 中找到此模块的其他配置提示和文档。