Nginx Web directory for handling Chinese files and folders and encoding format issues

Source: Internet
Author: User
Tags utf 8 openldap ultraedit

Sometimes the root directory of the site has a Chinese file name or folder, the client to access these related files will appear when the problem appears.

Here are some ways to fix it, available.

[Email protected] ~]#Echo $LANG
en_US. UTF-8
[Email protected] ~]# cat/etc/sysconfig/i18n
Lang= "en_US. UTF-8 "
Sysfont= "Latarcyrheb-sun16"
#LANG = "ZH_CN. GB18030 "
#LANGUAGE = "Zh_CN.GB18030:zh_CN.GB2312:zh_CN"
#SUPPORTED = "ZH_CN. Utf-8:zh_cn:zh:en_us. Utf-8:en_us:en "
#SYSFONT = "Lat0-sun16"
[Email protected] ~]#cat/etc/nginx/nginx.conf

User Nginx;
Worker_processes 2;

Error_log/var/log/nginx/error.log warn;
Pid/var/run/nginx.pid;


Events {
Worker_connections 1024;
}


HTTP {




Include/etc/nginx/mime.types;
Default_type Application/octet-stream;

Log_format Main ' $remote _addr-$remote _user [$time _local] "$request" '
' $status $body _bytes_sent ' $http _referer '
' "$http _user_agent" "$http _x_forwarded_for";

Access_log/var/log/nginx/access.log main;

Sendfile on;
#tcp_nopush on;

Keepalive_timeout 65;

#gzip on;
CharSet Utf-8;
include/etc/nginx/conf.d/*.conf;

At this time we need to convert the name of the folder and file in the site directory to the UTF-8 character set format. The tool CONVMV is used at this point.

CONVMV can be downloaded from HTTP://J3E.DE/LINUX/CONVMV,

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 file name above represents all files under Userfiles converted from GB2312 to UTF-8

Sometimes it is necessary to determine the file content encoding format is also UTF-8, can be vim to view the file encoding format.

######################################################################

CONVMV can help us easily encode and convert all the files in a file, a directory, such as GBK to UTF8.
Installing the Yum install CONVMV

Grammar:
CONVMV [Options] FILE (S) ... DIRECTORY (S)
Main options:
1,-F ENCODING
Specifies the encoding of the current file name, such as-f GBK
2,-t ENCODING
Specifies the encoding that will be converted, such as-f utf-8
3,-R
Recursively convert all filenames under directory
4 、--List
List all supported encodings
5 、--Notest
The default is to print only the converted effect, plus this option to actually perform the conversion operation.
Common parameters:-r Recursive Processing sub-folder –notest real operation, by default, does not do the actual operation of the file –list display all supported encodings –unescap can be escaped, such as the%20 into a space-I interactive mode (asking for each conversion, Prevent misoperation) How to use CONVMV: convmv-f source code-T new encoding [option] File name example: After this conversion "GBK encoded file name" will be converted to UTF-8 encoding (only the file name encoding conversion, the contents of the files will not change). Note: Do not use this command in NTFS and FAT file systems, otherwise it may produce unexpected results, and if you want to correctly display the names of NTFS and fat in Linux, you can resolve them by using the mount parameter, and refer to the man manual for details.

Example:
Recursively convert the current file name encoding GBK to Utf-8 in the CentOS directory:

1.convmv-f gbk-t utf-8--notest-r CentOS

2. code example: Convmv-f gbk-t UTF-8--notest-r 303i.com/* (303i.com/* is the current directory of files to be encoded)

Finally, you can search for related usage of CONVMV.

####################################################

If you need to operate files under Windows in Linux, you may often encounter problems with file encoding conversions. The default file format in Windows is GBK (gb2312), and Linux is generally UTF-8. Here's how to view the encoding of a file in Linux and how to encode and convert the file.

View File Encoding
There are several ways to view file encodings in Linux:
1. The file encoding can be viewed directly in vim
: Set fileencoding
You can display the file encoding format.
If you just want to see other encoded files or if you want to solve the problem of viewing files garbled with Vim, you can
Add the following to the ~/.VIMRC file:

Set Encoding=utf-8 fileencodings=ucs-bom,utf-8,cp936

This allows vim to automatically identify the file encoding (which automatically identifies the UTF-8 or GBK encoded file), in fact, in accordance with the fileencodings provided by the encoding list to try, if not found the appropriate encoding, the latin-1 (ASCII) encoding opened.
2. eNCA (if you do not have this command installed on your system, you can use sudo yum install-y eNCA installation) to view the file encoding
$ enca filename
Filename:universal Transformation Format 8 bits; UTF-8
CRLF Line Terminators
It is important to note that eNCA is not very good at identifying certain GBK encoded files and will appear when identified:
Unrecognized encoding

File Encoding Conversion
1. Convert file encoding directly into Vim, such as converting a file to Utf-8 format
: Set Fileencoding=utf-8

2. Enconv conversion file encoding, such as to convert a GBK encoded file into UTF-8 encoding, the operation is as follows
Enconv-l zh_cn-x UTF-8 filename

3. Iconv conversion, the ICONV command format is as follows:
Iconv-f ENCODING-T Encoding Inputfile
such as converting a UTF-8 encoded file into a GBK encoding.
Iconv-f gbk-t UTF-8 file1-o file2


Linux File name encoding conversion
Copying files from Linux to Windows, or copying files from Windows to Linux, sometimes the Chinese file name is garbled, the reason for this problem is because the Windows file name Chinese encoding defaults to GBK, and the default file name in Linux is encoded as UTF 8, because of inconsistent coding, so the file name garbled problem, to solve this problem requires the file name transcoding.

A tool convmv for file name encoding is provided specifically in Linux, which converts the file name from GBK to UTF-8 encoding, or from UTF-8 to GBK.

First look at whether the CONVMV is installed on your system, if it is not installed:
Yum-y Install CONVMV
Installation.
Here's a look at the specific usage of CONVMV:

Convmv-f Source code-T new encoding [options] File name

Common parameters:
-R recursive processing of subfolders
--notest the actual operation, please note that by default, the file does not actually operate, but only the experiment.
--list display of all supported encodings
--unescap can be escaped, such as to turn%20 into a space
For example, we have a UTF8 encoded file name, converted to GBK encoding, the command is as follows:

Convmv-f UTF-8-T GBK--notest UTF8 encoded file name

After this conversion, the "UTF8 encoded file name" will be converted to GBK encoding (only the filename-encoded conversion, the file content will not be changed).

Dos and UNIX text file formats

The DOS and UNIX text file format is primarily a carriage return encoding in different ways. Originally, the carriage return under UNIX is represented by 0x0a, while the carriage return under DOS is 0x0d0a. Can be viewed using the hex editor in UltraEdit. Problems encountered in the actual work.                                                                             The OpenLDAP boot file needs to get the directory of the data files from the configuration file slapd.conf. ·  Lang=c grep ' ^directory[[:space:]]+[[:p rint:] '/etc/openldap/slapd_pri.conf | Sed s,^directory,, does not always get the Directroy value correctly in DOS format.

Conversion method: 1. In Windows, you can save UltraEdit in UNIX format. In Linux, you can use the Dos2unix tool to convert.

2. Use VIM to convert, open text file with VIM, convert with Set Fileformat=unix
Vim Test.txt
: Set Fileformat=unix
: Wq






































Nginx Web directory for handling Chinese files and folders and encoding format issues

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.