Windows下nginx访问页面 中文乱码 解决方案


今天在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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM