首页 > 解决方案 > 为什么我不能在 nginx 中正常显示 CJK 字符?

问题描述

环境:Windows 10 + nginx/1.8.0。目录下的文件mysql都是 UTF-8 编码,所有 HTML 文件都mysql包含 <meta charset="utf-8" />.

我的文件nginx.conf的配置文件:

worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
        charset gbk,utf-8;
        source_charset gbk,utf-8;
        autoindex on;
        location / {
            root   d:/mydoc/build/html;
            index  index.html index.htm;
            charset gbk,utf-8;
            source_charset gbk,utf-8;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

mysql我启动我的 nginx 服务器并在 Firefox 中打开目录:

在此处输入图像描述

所有 CJK 字符均正确显示。现在点击第三个第三个标题---- mysql日志.html

在此处输入图像描述

显示文件error.log以检查发生了什么:

2020/12/05 22:41:19 [error] 11252#11076: *8 CreateFile() "d:/mydoc/build/html/mysql/mysql日志.html" failed
(2: The system cannot find the file specified),
client: 127.0.0.1, server: localhost, request:
"GET /mysql/mysql%C8%D5%D6%BE.html HTTP/1.1", host: "127.0.0.1", referrer: "http://127.0.0.1/mysql/"

http://127.0.0.1/mysql/mysql日志.html在我的 Firefox 中输入并单击。所有 CJK 字符均正确显示。

在此处输入图像描述

如何解决点击title in时跳转到包含乱码CJK字符的网页的问题127.0.0.1/mysql

经验证,对于相同的目录和文件,CJK 字符可以在nginx + Linux而不是nginx + Windows中正确显示。

标签: nginxcjk

解决方案


按照alibabacloud guide,我最好的猜测是您应该只使用charset utf-8并且您还应该检查所有文件名是否为 UTF-8 格式或转换为 UTF-8 否则(仅文件名,而不是内容)。


推荐阅读