NGINX 增加charset=utf-8

 

由于部分老设备页面编码不是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_mapcharset, or source_charset directives. For utf-8windows-1251, and koi8-r charsets, it is sufficient to include the files conf/koi-winconf/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_headersfastcgi_ignore_headersuwsgi_ignore_headersscgi_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”.
posted @ 2020-11-23 14:12  伟成  阅读(5722)  评论(0编辑  收藏  举报