Lighttpd 为 UTF-8 内容发送错误的标头

M. *_*ley 8 lighttpd utf-8

Ubuntu/Lighttpd 没有为我的 UTF-8 编码文件提供正确的Content-Type标头。它是发送Content-Type: text/html而不是Content-Type: text/html; charset=UTF-8. 如何配置 Lighttpd 以发送正确的标头?

我在默认设置中没有看到任何有用的设置,lighttpd.conf并且无法在文档中找到信息。

M. *_*ley 8

默认lighttpd.conf文件似乎/etc/mime.types使用 perl 脚本加载 MIME 类型:

include_shell "/usr/share/lighttpd/create-mime.assign.pl"
Run Code Online (Sandbox Code Playgroud)

在我的文件中,/etc/mime.types我的html文件被设置为text/html. 我注释掉了include_shellperl 脚本并将以下mimetype.assign条目添加到lighttpd.conf

mimetype.assign = ( ".html" => "text/html; charset=utf-8" )
Run Code Online (Sandbox Code Playgroud)

我不确定是否有更优雅的解决方案。使用这种方法,我需要复制所有条目/etc/mime.types以保留其他 MIME 类型映射。


小智 5

我遇到了同样的问题,终于在博客上找到了解决方案

基本上它是上面提到的 perl 脚本的拉皮条版本,它将 charset=utf-8 声明添加到所有以“text/”开头的 mime-types 只需替换 perl 脚本并重新启动 lig​​httpd。