How do I get Nginx to support Chinese file names

  • 2020-05-06 12:16:42
  • OfStack

The first thing to do is to have your system with a Chinese language package:

Before setting: locale check, if the display is en_US.UTF-8, that is normal, do not follow the following steps to set. If other encodings are displayed, follow these steps.

CentOS

Edit/etc/sysconfig/i18n files, content is amended as: (can use vi, nano or winscp graphics management software, according to personal taste
choice)
LANG="en_US.UTF-8"

SYSFONT="latarcyrheb-sun16"

Save and restart the system.

Debian

apt-get install -y locales

dpkg-reconfigure locales

After executing dpkg-reconfigure locales, the following dialog box appears:

Use the down key to find en_US.UTF-8 UTF-8, press space to select, and then press enter.

Then press the down key to select en_US.UTF-8, then press enter to confirm and restart the system.

Ubuntu

Edit the /etc/default/locale file to (create one if you don't have one) :

LANG="en_US.UTF-8"

LANGUAGE="en_US:en"

Save and execute:

locale-gen en_US en_US.UTF-8

Restart the system.

Execution: locale check to see if it shows en_US.UTF-8. If there is an error, please feedback in this article. Follow the above steps to set up after you can support Chinese, you can upload Chinese files or Chinese directory.

The character set configured in the nginx.conf file is also utf-8

server {

listen 80;

server_name test.cn;

root /data;

index index.html index.jsp;

charset utf-8;

...

ay%PM'G+U0

The client USES secureCRT, and the character set is changed to utf-8. After uft-8, the file is uploaded by rz. The Chinese can be displayed normally under ie.

Note:

If the Chinese file name is gb2312, it needs to be converted to utf-8. Using convmv conversion, (if you can't find this command, CD in the package convmv - 1.10-1. el5. noarch. rpm) convmv - fGBK - tUTF8 - r - notesttarget

Where -f is the source code, -t is the target code, -r is the recursive processing directory, and the -notest is not moving, actually renaming the file (actually do rename the files), target is the target directory. The remaining parameters can be referred to man or -h.

If it is the file uploaded before changing the code, it will still be garbled after setting it up. It is recommended to upload the file again. If there is no backup of the original file, the following command can be used for conversion: for f in 'ls *.html'; do mv $f 'ls $f done.

Where *.html is the file type to be converted, you can also change to *.txt, *.

If you want to change it under Windows, you can actually change it. Editplus has the function of batch changing the file encoding. Other software may also have such function.

If it is a directory, there seems to be no way to convert at present.

Another problem is that if it is a web file like html, and if the original web content is the encoding of gb2312 or similar non-utf-8, first change the charset in the web page to charset= utf-8, and then change the file encoding, otherwise the web page will still be scrambled.

convmv from http: / / j3e de linux/convmv download,

wget http://j3e.de/linux/convmv/convmv-1.14.tar.gz

tar -zxvf convmv-1.14.tar.gz

cd convmv-1.14

make clean;

make install;

Such as:

./convmv -f GB2312 -t UTF-8 -r --nosmart --notest userfiles/*.*

The above means that the file names of all files under userfiles are converted from GB2312 to UTF-8

iconv can be used for character set conversion of file contents

Related articles: