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.
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>
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; } }
Modify the nginx configuration file and reload it Check nginx
nginx -s reload
Last access test: Chinese parsing is normal.
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!