今天在Windows服務器的Nginx上部署一個小網頁項目時,中文出現亂碼,搜了一下,網上解決方法都是一樣 千篇一律
改服務端的編碼格式。
這里總結一下解決方法:出現亂碼可能由於以下兩個位置沒有配置編碼格式:
1、網頁代碼設置utf-8編碼格式,如下。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>中文標題</title>
</head>
<body>
<center>微信搜索:蝸牛linux</center>
</body>
</html>
2、nginx服務端,nginx.conf設置gbk編碼格式:注意server層 和 訪問路徑location都要配置一下
server {
listen 81;
set $root F:/Develop/nginx-1.14.0/html;
root $root;
server_name localhost;
access_log logs/host.access.log main;
index index.html index.php;
#設置字符集
charset gbk;#如果是Linux請設置為utf-8
location / {
root html;
index index.html index.htm;
charset gbk;#如果是Linux請設置為utf-8
}
}
修改了nginx的配置文件,重新加載一下nginx
nginx -s reload
來源:https://blog.csdn.net/weixin_42350212/article/details/107359891