nginx的页面中文乱码解决方法 -尊龙游戏旗舰厅官网
在server段里加以下
charset utf-8;
然后重启就行了
sudo nginx -s reload
mime-type和content-type的关系:
当web服务器收到静态的资源文件请求时,依据请求文件的后缀名在服务器的mime配置文件中找到对应的mime type,再根据mime type设置http response的content-type,然后浏览器根据content-type的值处理文件。
什么是mime-type:
为什么这么说呢?首先,我们要了解浏览器是如何处理内容的。在浏览器中显示的内容有 html、有 xml、有 gif、还有 flash ...
那么,浏览器是如何区分它们,决定什么内容用什么形式来显示呢?答案是 mime type,也就是该资源的媒体类型。
媒体类型通常是通过 http 协议,由 web 服务器告知浏览器的,更准确地说,是通过 content-type 来表示的,例如:
content-type: text/html
表 示内容是 text/html 类型,也就是超文本文件。为什么是“text/html”而不是“html/text”或者别的什么?mime type 不是个人指定的,是经过 ietf 组织协商,以 rfc 的形式作为建议的标准发布在网上的,大多数的 web 服务器和用户代理都会支持这个规范 (顺便说一句,email 附件的类型也是通过 mime type 指定的)。
通常只有一些在互联网上获得广泛应用的格式才会获得一个 mime type,如果是某个客户端自己定义的格式,一般只能以 application/x- 开头。
xhtml 正是一个获得广泛应用的格式,因此,在 rfc 3236 中,说明了 xhtml 格式文件的 mime type 应该是 application/xhtml xml。
当 然,处理本地的文件,在没有人告诉浏览器某个文件的 mime type 的情况下,浏览器也会做一些默认的处理,这可能和你在操作系统中给文件配置的 mime type 有关。比如在 windows 下,打开注册表的“hkey_local_machinesoftwareclassesmimedatabasecontent type”主键,你可以看到所有 mime type 的配置信息。
nginx中设置默认的mime-type(在nginx.conf中)
default_type
syntax: default_type mime-type
default: default_type text/plain
context: http, server, location
assigns the default mime-type to be used for files where the standard mime map doesn't specify anything.
example:
location = /proxy.pac {
default_type application/x-ns-proxy-autoconfig;
}
location = /wpad.dat {
rewrite . /proxy.pac;
default_type application/x-ns-proxy-autoconfig;mime-type和content-type的关系:
当web服务器收到静态的资源文件请求时,依据请求文件的后缀名在服务器的mime配置文件中找到对应的mime type,再根据mime type设置http response的content-type,然后浏览器根据content-type的值处理文件。
转载于:https://blog.51cto.com/3105610/1740257
总结
以上是尊龙游戏旗舰厅官网为你收集整理的nginx的页面中文乱码解决方法的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: android自动化测试-从入门到入门(
- 下一篇: php redis 集群封装类