Path: blob/main/xml/en/docs/http/ngx_http_charset_module.xml
1 views
<?xml version="1.0"?>12<!--3Copyright (C) Igor Sysoev4Copyright (C) Nginx, Inc.5-->67<!DOCTYPE module SYSTEM "../../../../dtd/module.dtd">89<module name="Module ngx_http_charset_module"10link="/en/docs/http/ngx_http_charset_module.html"11lang="en"12rev="5">1314<section id="summary">1516<para>17The <literal>ngx_http_charset_module</literal> module adds the specified18charset to the <header>Content-Type</header> response header field.19In addition, the module can convert data from one charset to another,20with some limitations:21<list type="bullet">2223<listitem>24conversion is performed one way — from server to client,25</listitem>2627<listitem>28only single-byte charsets can be converted29</listitem>3031<listitem>32or single-byte charsets to/from UTF-8.33</listitem>3435</list>36</para>3738</section>394041<section id="example" name="Example Configuration">4243<para>44<example>45include conf/koi-win;4647charset windows-1251;48source_charset koi8-r;49</example>50</para>5152</section>535455<section id="directives" name="Directives">5657<directive name="charset">58<syntax><value>charset</value> | <literal>off</literal></syntax>59<default>off</default>60<context>http</context>61<context>server</context>62<context>location</context>63<context>if in location</context>6465<para>66Adds the specified charset to the <header>Content-Type</header>67response header field.68If this charset is different from the charset specified69in the <link id="source_charset"/> directive, a conversion is performed.70</para>7172<para>73The parameter <literal>off</literal> cancels the addition of charset74to the <header>Content-Type</header> response header field.75</para>7677<para>78A charset can be defined with a variable:79<example>80charset $charset;81</example>82In such a case, all possible values of a variable need to be present83in the configuration at least once in the form of the84<link id="charset_map"/>, <link id="charset"/>, or85<link id="source_charset"/> directives.86For <literal>utf-8</literal>, <literal>windows-1251</literal>, and87<literal>koi8-r</literal> charsets, it is sufficient to include the files88<path>conf/koi-win</path>, <path>conf/koi-utf</path>, and89<path>conf/win-utf</path> into configuration.90For other charsets, simply making a fictitious conversion table works,91for example:92<example>93charset_map iso-8859-5 _ { }94</example>95</para>9697<para>98In addition, a charset can be set in the99<header>X-Accel-Charset</header> response header field.100This capability can be disabled using the101<link doc="ngx_http_proxy_module.xml" id="proxy_ignore_headers"/>,102<link doc="ngx_http_fastcgi_module.xml" id="fastcgi_ignore_headers"/>,103<link doc="ngx_http_uwsgi_module.xml" id="uwsgi_ignore_headers"/>,104<link doc="ngx_http_scgi_module.xml" id="scgi_ignore_headers"/>,105and106<link doc="ngx_http_grpc_module.xml" id="grpc_ignore_headers"/>107directives.108</para>109110</directive>111112113<directive name="charset_map">114<syntax block="yes"><value>charset1</value> <value>charset2</value></syntax>115<default/>116<context>http</context>117118<para>119Describes the conversion table from one charset to another.120A reverse conversion table is built using the same data.121Character codes are given in hexadecimal.122Missing characters in the range 80-FF are replaced with “<literal>?</literal>”.123When converting from UTF-8, characters missing in a one-byte charset124are replaced with “<literal>&#XXXX;</literal>”.125</para>126127<para>128Example:129<example>130charset_map koi8-r windows-1251 {131C0 FE ; # small yu132C1 E0 ; # small a133C2 E1 ; # small b134C3 F6 ; # small ts135...136}137</example>138</para>139140<para>141When describing a conversion table to UTF-8, codes for the UTF-8 charset should142be given in the second column, for example:143<example>144charset_map koi8-r utf-8 {145C0 D18E ; # small yu146C1 D0B0 ; # small a147C2 D0B1 ; # small b148C3 D186 ; # small ts149...150}151</example>152</para>153154<para>155Full conversion tables from <literal>koi8-r</literal> to156<literal>windows-1251</literal>, and from <literal>koi8-r</literal> and157<literal>windows-1251</literal> to <literal>utf-8</literal>158are provided in the distribution files <path>conf/koi-win</path>,159<path>conf/koi-utf</path>, and <path>conf/win-utf</path>.160</para>161162</directive>163164165<directive name="charset_types">166<syntax><value>mime-type</value> ...</syntax>167<default>text/html text/xml text/plain text/vnd.wap.wml168application/javascript application/rss+xml</default>169<context>http</context>170<context>server</context>171<context>location</context>172<appeared-in>0.7.9</appeared-in>173174<para>175Enables module processing in responses with the specified MIME types176in addition to “<literal>text/html</literal>”.177The special value “<literal>*</literal>” matches any MIME type (0.8.29).178</para>179180<para>181<note>182Until version 1.5.4, “<literal>application/x-javascript</literal>” was used183as the default MIME type instead of “<literal>application/javascript</literal>”.184</note>185</para>186187</directive>188189190<directive name="override_charset">191<syntax><literal>on</literal> | <literal>off</literal></syntax>192<default>off</default>193<context>http</context>194<context>server</context>195<context>location</context>196<context>if in location</context>197198<para>199Determines whether a conversion should be performed for answers200received from a proxied or a FastCGI/uwsgi/SCGI/gRPC server201when the answers already carry a charset in the <header>Content-Type</header>202response header field.203If conversion is enabled, a charset specified in the received204response is used as a source charset.205<note>206It should be noted that if a response is received in a subrequest207then the conversion from the response charset to the main request charset208is always performed, regardless of the <literal>override_charset</literal>209directive setting.210</note>211</para>212213</directive>214215216<directive name="source_charset">217<syntax><value>charset</value></syntax>218<default/>219<context>http</context>220<context>server</context>221<context>location</context>222<context>if in location</context>223224<para>225Defines the source charset of a response.226If this charset is different from the charset specified227in the <link id="charset"/> directive, a conversion is performed.228</para>229230</directive>231232</section>233234</module>235236237