summaryrefslogtreecommitdiff
path: root/pod/nginx/ngx_http_charset_module.pod
blob: 8c241b0fd16305d3ae616b1ee05c6010b7a30af6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
=encoding utf-8

=head1 NAME

ngx_http_charset_module - Module ngx_http_charset_module




=head1



The C<ngx_http_charset_module> module adds the specified
charset to the C<Content-Type> response header field.
In addition, the module can convert data from one charset to another,
with some limitations:

=over




=item *

conversion is performed one way — from server to client,



=item *

only single-byte charsets can be converted



=item *

or single-byte charsets toE<sol>from UTF-8.



=back






=head1 Example Configuration




    
    include        conf/koi-win;
    
    charset        windows-1251;
    source_charset koi8-r;






=head1 Directives

=head2 charset


B<syntax:> charset I<I<C<charset>> E<verbar> C<off>>


B<default:> I<off>


B<context:> I<http>


B<context:> I<server>


B<context:> I<location>


B<context:> I<if in location>





Adds the specified charset to the C<Content-Type>
response header field.
If this charset is different from the charset specified
in the L</source_charset> directive, a conversion is performed.





The parameter C<off> cancels the addition of charset
to the C<Content-Type> response header field.





A charset can be defined with a variable:

    
    charset $charset;


In such a case, all possible values of a variable need to be present
in the configuration at least once in the form of the
L</charset_map>, L</charset>, or
L</source_charset> directives.
For C<utf-8>, C<windows-1251>, and
C<koi8-r> charsets, it is sufficient to include the files
F<confE<sol>koi-win>, F<confE<sol>koi-utf>, and
F<confE<sol>win-utf> into configuration.
For other charsets, simply making a fictitious conversion table works,
for example:

    
    charset_map iso-8859-5 _ { }







In addition, a charset can be set in the
C<X-Accel-Charset> response header field.
This capability can be disabled using the
L<ngx_http_proxy_module>,
L<ngx_http_fastcgi_module>,
L<ngx_http_uwsgi_module>,
L<ngx_http_scgi_module>,
and
L<ngx_http_grpc_module>
directives.







=head2 charset_map


B<syntax:> charset_map I<I<C<charset1>> I<C<charset2>> { B<...> } >



B<context:> I<http>





Describes the conversion table from one charset to another.
A reverse conversion table is built using the same data.
Character codes are given in hexadecimal.
Missing characters in the range 80-FF are replaced with “C<?>”.
When converting from UTF-8, characters missing in a one-byte charset
are replaced with “C<E<amp>#XXXX;>”.





Example:

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







When describing a conversion table to UTF-8, codes for the UTF-8 charset should
be given in the second column, for example:

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







Full conversion tables from C<koi8-r> to
C<windows-1251>, and from C<koi8-r> and
C<windows-1251> to C<utf-8>
are provided in the distribution files F<confE<sol>koi-win>,
F<confE<sol>koi-utf>, and F<confE<sol>win-utf>.







=head2 charset_types


B<syntax:> charset_types I<I<C<mime-type>> ...>


B<default:> I<textE<sol>html textE<sol>xml textE<sol>plain textE<sol>vnd.wap.wml
applicationE<sol>javascript applicationE<sol>rss+xml>


B<context:> I<http>


B<context:> I<server>


B<context:> I<location>



This directive appeared in version 0.7.9.





Enables module processing in responses with the specified MIME types
in addition to “C<textE<sol>html>”.
The special value “C<*>” matches any MIME type (0.8.29).






B<NOTE>

Until version 1.5.4, “C<applicationE<sol>x-javascript>” was used
as the default MIME type instead of “C<applicationE<sol>javascript>”.








=head2 override_charset


B<syntax:> override_charset I<C<on> E<verbar> C<off>>


B<default:> I<off>


B<context:> I<http>


B<context:> I<server>


B<context:> I<location>


B<context:> I<if in location>





Determines whether a conversion should be performed for answers
received from a proxied or a FastCGIE<sol>uwsgiE<sol>SCGIE<sol>gRPC server
when the answers already carry a charset in the C<Content-Type>
response header field.
If conversion is enabled, a charset specified in the received
response is used as a source charset.

B<NOTE>

It should be noted that if a response is received in a subrequest
then the conversion from the response charset to the main request charset
is always performed, regardless of the C<override_charset>
directive setting.








=head2 source_charset


B<syntax:> source_charset I<I<C<charset>>>



B<context:> I<http>


B<context:> I<server>


B<context:> I<location>


B<context:> I<if in location>





Defines the source charset of a response.
If this charset is different from the charset specified
in the L</charset> directive, a conversion is performed.