Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
nginx
GitHub Repository: nginx/nginx.org
Path: blob/main/xml/en/docs/http/ngx_http_charset_module.xml
1 views
1
<?xml version="1.0"?>
2
3
<!--
4
Copyright (C) Igor Sysoev
5
Copyright (C) Nginx, Inc.
6
-->
7
8
<!DOCTYPE module SYSTEM "../../../../dtd/module.dtd">
9
10
<module name="Module ngx_http_charset_module"
11
link="/en/docs/http/ngx_http_charset_module.html"
12
lang="en"
13
rev="5">
14
15
<section id="summary">
16
17
<para>
18
The <literal>ngx_http_charset_module</literal> module adds the specified
19
charset to the <header>Content-Type</header> response header field.
20
In addition, the module can convert data from one charset to another,
21
with some limitations:
22
<list type="bullet">
23
24
<listitem>
25
conversion is performed one way — from server to client,
26
</listitem>
27
28
<listitem>
29
only single-byte charsets can be converted
30
</listitem>
31
32
<listitem>
33
or single-byte charsets to/from UTF-8.
34
</listitem>
35
36
</list>
37
</para>
38
39
</section>
40
41
42
<section id="example" name="Example Configuration">
43
44
<para>
45
<example>
46
include conf/koi-win;
47
48
charset windows-1251;
49
source_charset koi8-r;
50
</example>
51
</para>
52
53
</section>
54
55
56
<section id="directives" name="Directives">
57
58
<directive name="charset">
59
<syntax><value>charset</value> | <literal>off</literal></syntax>
60
<default>off</default>
61
<context>http</context>
62
<context>server</context>
63
<context>location</context>
64
<context>if in location</context>
65
66
<para>
67
Adds the specified charset to the <header>Content-Type</header>
68
response header field.
69
If this charset is different from the charset specified
70
in the <link id="source_charset"/> directive, a conversion is performed.
71
</para>
72
73
<para>
74
The parameter <literal>off</literal> cancels the addition of charset
75
to the <header>Content-Type</header> response header field.
76
</para>
77
78
<para>
79
A charset can be defined with a variable:
80
<example>
81
charset $charset;
82
</example>
83
In such a case, all possible values of a variable need to be present
84
in the configuration at least once in the form of the
85
<link id="charset_map"/>, <link id="charset"/>, or
86
<link id="source_charset"/> directives.
87
For <literal>utf-8</literal>, <literal>windows-1251</literal>, and
88
<literal>koi8-r</literal> charsets, it is sufficient to include the files
89
<path>conf/koi-win</path>, <path>conf/koi-utf</path>, and
90
<path>conf/win-utf</path> into configuration.
91
For other charsets, simply making a fictitious conversion table works,
92
for example:
93
<example>
94
charset_map iso-8859-5 _ { }
95
</example>
96
</para>
97
98
<para>
99
In addition, a charset can be set in the
100
<header>X-Accel-Charset</header> response header field.
101
This capability can be disabled using the
102
<link doc="ngx_http_proxy_module.xml" id="proxy_ignore_headers"/>,
103
<link doc="ngx_http_fastcgi_module.xml" id="fastcgi_ignore_headers"/>,
104
<link doc="ngx_http_uwsgi_module.xml" id="uwsgi_ignore_headers"/>,
105
<link doc="ngx_http_scgi_module.xml" id="scgi_ignore_headers"/>,
106
and
107
<link doc="ngx_http_grpc_module.xml" id="grpc_ignore_headers"/>
108
directives.
109
</para>
110
111
</directive>
112
113
114
<directive name="charset_map">
115
<syntax block="yes"><value>charset1</value> <value>charset2</value></syntax>
116
<default/>
117
<context>http</context>
118
119
<para>
120
Describes the conversion table from one charset to another.
121
A reverse conversion table is built using the same data.
122
Character codes are given in hexadecimal.
123
Missing characters in the range 80-FF are replaced with “<literal>?</literal>”.
124
When converting from UTF-8, characters missing in a one-byte charset
125
are replaced with “<literal>&amp;#XXXX;</literal>”.
126
</para>
127
128
<para>
129
Example:
130
<example>
131
charset_map koi8-r windows-1251 {
132
C0 FE ; # small yu
133
C1 E0 ; # small a
134
C2 E1 ; # small b
135
C3 F6 ; # small ts
136
...
137
}
138
</example>
139
</para>
140
141
<para>
142
When describing a conversion table to UTF-8, codes for the UTF-8 charset should
143
be given in the second column, for example:
144
<example>
145
charset_map koi8-r utf-8 {
146
C0 D18E ; # small yu
147
C1 D0B0 ; # small a
148
C2 D0B1 ; # small b
149
C3 D186 ; # small ts
150
...
151
}
152
</example>
153
</para>
154
155
<para>
156
Full conversion tables from <literal>koi8-r</literal> to
157
<literal>windows-1251</literal>, and from <literal>koi8-r</literal> and
158
<literal>windows-1251</literal> to <literal>utf-8</literal>
159
are provided in the distribution files <path>conf/koi-win</path>,
160
<path>conf/koi-utf</path>, and <path>conf/win-utf</path>.
161
</para>
162
163
</directive>
164
165
166
<directive name="charset_types">
167
<syntax><value>mime-type</value> ...</syntax>
168
<default>text/html text/xml text/plain text/vnd.wap.wml
169
application/javascript application/rss+xml</default>
170
<context>http</context>
171
<context>server</context>
172
<context>location</context>
173
<appeared-in>0.7.9</appeared-in>
174
175
<para>
176
Enables module processing in responses with the specified MIME types
177
in addition to “<literal>text/html</literal>”.
178
The special value “<literal>*</literal>” matches any MIME type (0.8.29).
179
</para>
180
181
<para>
182
<note>
183
Until version 1.5.4, “<literal>application/x-javascript</literal>” was used
184
as the default MIME type instead of “<literal>application/javascript</literal>”.
185
</note>
186
</para>
187
188
</directive>
189
190
191
<directive name="override_charset">
192
<syntax><literal>on</literal> | <literal>off</literal></syntax>
193
<default>off</default>
194
<context>http</context>
195
<context>server</context>
196
<context>location</context>
197
<context>if in location</context>
198
199
<para>
200
Determines whether a conversion should be performed for answers
201
received from a proxied or a FastCGI/uwsgi/SCGI/gRPC server
202
when the answers already carry a charset in the <header>Content-Type</header>
203
response header field.
204
If conversion is enabled, a charset specified in the received
205
response is used as a source charset.
206
<note>
207
It should be noted that if a response is received in a subrequest
208
then the conversion from the response charset to the main request charset
209
is always performed, regardless of the <literal>override_charset</literal>
210
directive setting.
211
</note>
212
</para>
213
214
</directive>
215
216
217
<directive name="source_charset">
218
<syntax><value>charset</value></syntax>
219
<default/>
220
<context>http</context>
221
<context>server</context>
222
<context>location</context>
223
<context>if in location</context>
224
225
<para>
226
Defines the source charset of a response.
227
If this charset is different from the charset specified
228
in the <link id="charset"/> directive, a conversion is performed.
229
</para>
230
231
</directive>
232
233
</section>
234
235
</module>
236
237