由於部分老設備頁面編碼不是utf-8 ,導致頁面亂碼。 通過配置nginx的charset 對設備進行兼容。
期間發現單純charset utf-8 的配置並不能使請求生效。與網上看到的攻略存在差異,特此輸出本文。
最后生效的配置:
- charset_types * ; # 由於1.5.4版本開始默認MIME type 為“
application/x-javascript
” ,通過 * 號覆蓋text/css 、 application/javascript - charset utf-8 ; # 默認為 off
官方參數說明:
Syntax: charset charset | off; Default: charset off; Context: http, server, location, if in location
Adds the specified charset to the “Content-Type” response header field. If this charset is different from the charset specified in the source_charset directive, a conversion is performed.
The parameter off
cancels the addition of charset to the “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 charset_map, charset, or source_charset directives. For utf-8
, windows-1251
, and koi8-r
charsets, it is sufficient to include the files conf/koi-win
, conf/koi-utf
, and conf/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 “X-Accel-Charset” response header field. This capability can be disabled using the proxy_ignore_headers, fastcgi_ignore_headers, uwsgi_ignore_headers, scgi_ignore_headers, and grpc_ignore_headers directives.
Syntax: charset_types mime-type ...; Default: charset_types text/html text/xml text/plain text/vnd.wap.wml application/javascript application/rss+xml; Context: http, server, location
This directive appeared in version 0.7.9.
Enables module processing in responses with the specified MIME types in addition to “text/html
”. The special value “*
” matches any MIME type (0.8.29).
Until version 1.5.4, “application/x-javascript
” was used as the default MIME type instead of “application/javascript
”.