Character encoding 使用Lighttpd在HTTP标头中指定字符集
我试图在Lighttpd设置的HTTP头中指定一个字符集。我在StackExchange的网站上找到了很多建议 1。尝试查找Character encoding 使用Lighttpd在HTTP标头中指定字符集,character-encoding,debian,mime-types,lighttpd,Character Encoding,Debian,Mime Types,Lighttpd,我试图在Lighttpd设置的HTTP头中指定一个字符集。我在StackExchange的网站上找到了很多建议 1。尝试查找mime.types文件,因此我可以添加;charset=utf-8在我想要在HTTP头中为其指定字符集的任何文件类型的末尾,但是mime.types-file看起来与我预期的完全不同: 2.尝试从以下内容更改创建mime.assign.pl: #!/usr/bin/perl -w use strict; open MIMETYPES, "/etc/mime.types"
mime.types
文件,因此我可以添加;charset=utf-8
在我想要在HTTP头中为其指定字符集的任何文件类型的末尾,但是mime.types-file看起来与我预期的完全不同:
2.尝试从以下内容更改创建mime.assign.pl
:
#!/usr/bin/perl -w
use strict;
open MIMETYPES, "/etc/mime.types" or exit;
print "mimetype.assign = (\n";
my %extensions;
while(<MIMETYPES>) {
chomp;
s/\#.*//;
next if /^\w*$/;
if(/^([a-z0-9\/+-.]+)\s+((?:[a-z0-9.+-]+[ ]?)+)$/) {
foreach(split / /, $2) {
# mime.types can have same extension for different
# mime types
next if $extensions{$_};
$extensions{$_} = 1;
print "\".$_\" => \"$1\",\n";
}
}
}
print ")\n";
它给了我一个错误,无法重新启动Lighttpd服务器,因为它发现了“mimetype.assign”变量的重复配置变量-一个在create-mime.assign.pl中,另一个在Lighttpd.conf中。我知道我可以尝试从lighttpd.conf中删除include\u shell”/usr/share/lighttpd/create mime.assign.pl“
,这样就不会有任何重复的配置变量,但是其他所有mime类型呢
一般信息:
- Lighttpd版本:1.4.28
- PHP版本:5.3.29-1
- Linux:Debian6.0
- Lighttpd.conf:
doc/scripts/create mime.conf.pl
包含一个扩展列表,其中添加了“charset=utf-8”
充当“text/…;charset=utf-8”的子类型
#不包括text/html:html有自己的定义字符集的方法
#(),但标准规定HTTP中的内容类型占优势
#html文档中的设置。
我的%text\u utf8=map{$\uf8=>1}qw(#……)。。。。。。
您可以在git源代码中找到它:Debian 9上的lighttpd 1.4.45-1没有提供该文件。
/usr/share/lighttpd/create mime.assign.pl
没有任何utf-8处理。Debian包lighttpd 1.4.52-2使用create-mime.conf.pl,并且该(或更高版本)将是Debian Buster的一部分。
#!/usr/bin/perl -w
use strict;
open MIMETYPES, "/etc/mime.types" or exit;
print "mimetype.assign = (\n";
my %extensions;
while(<MIMETYPES>) {
chomp;
s/\#.*//;
next if /^\w*$/;
if(/^([a-z0-9\/+-.]+)\s+((?:[a-z0-9.+-]+[ ]?)+)$/) {
my $pup = $1;
foreach(split / /, $2) {
# mime.types can have same extension for different
# mime types
next if $extensions{$_};
next if not defined $pup;
next if $pup eq '';
$extensions{$_} = 1;
if ($pup =~ /^text\//) {
print "\".$_\" => \"$pup; charset=utf-8\",\n";
} else {
print "\".$_\" => \"$pup\",\n";
}
}
}
}
print ")\n";
mimetype.assign = (
".css" => "text/css; charset=utf-8",
".html" => "text/html; charset=utf-8",
".htm" => "text/html; charset=utf-8",
".js" => "text/javascript; charset=utf-8",
".text" => "text/plain; charset=utf-8",
".txt" => "text/plain; charset=utf-8",
".xml" => "text/xml; charset=utf-8"
)
# text/* subtypes to serve as "text/...; charset=utf-8"
# text/html IS NOT INCLUDED: html has its own method for defining charset
# (<meta>), but the standards specify that content-type in HTTP wins over
# the setting in the html document.
my %text_utf8 = map { $_ => 1 } qw( # ......