提出问题
html可能正常显示中文,因为有<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
但 .css、.js中的中文,不能正常显示,显示乱码
解决
查看nginx的核心配置nginx.conf
根据include /etc/nginx/conf.d/*.conf;配置,确定server配置文件所在路径
执行
ls /etc/nginx/conf.d/
确定要修改 default.conf 配置文件,在该文件增加charset utf-8;,即:设置utf-8编码。
注意: 其他内容不用修改
该配置文件完整内容如下:
server {
listen 80; # 监听所有ipv4的80端口
listen [::]:80; # 监听所有ipv6的80端口
server_name localhost; # 匹配域名。主机绑定多个域名时使用
charset utf-8; # 设置utf-8
location / {
root /usr/share/nginx/html;
index index.html index.htm; # 默认首页是 index.html 或 index.htm
}
}