What to do if nginx php Chinese garbled characters

藏色散人
Release: 2023-03-12 17:18:02
Original
3647 people have browsed it

nginx PHP Chinese garbled solution: 1. Set the web page code to utf-8 encoding format; 2. Set the utf-8 encoding format in the nginx server and nginx.conf.

What to do if nginx php Chinese garbled characters

The operating environment of this article: linux5.9.8 system, nginx1.14.0 version, Dell G3 computer

nginx What to do if php Chinese garbled characters ?

#Solution to Chinese garbled characters on nginx access page

Today when deploying a small web page project on nginx, Chinese characters appeared garbled. I searched and found a solution online. The methods are all the same

Change the encoding format of the server.

Here is a summary of the solution: garbled characters may occur because the encoding format is not configured in the following two locations:

1. The web page code sets the utf-8 encoding format, as follows.

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
     <title>中文标题</title>
</head>
<body>
    <center>微信搜索:蜗牛linux</center>
</body>
</html>
Copy after login

2. nginx server, nginx.conf sets the utf-8 encoding format: note that the server layer and access path location must be configured

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 utf-8;
        location / {
            root html;
            index index.html index.htm;
            charset utf-8;
        }
    }
Copy after login

Modify the nginx configuration file and reload it Check nginx

nginx -s reload
Copy after login

Last access test: Chinese parsing is normal.

What to do if nginx php Chinese garbled characters

The above is the detailed content of What to do if nginx php Chinese garbled characters. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template