Httpd服务入门知识-Httpd服务常见配置案例之设定默认字符集

          Httpd服务入门知识-Httpd服务常见配置案例之设定默认字符集

                                                作者:尹正杰

版权声明:原创作品,谢绝转载!否则将追究法律责任。

一.查看生产环境中使用的字符集案例

1>.查看腾讯设置的默认字符集

Httpd服务入门知识-Httpd服务常见配置案例之设定默认字符集

2>.查看京东设置的默认字符集

Httpd服务入门知识-Httpd服务常见配置案例之设定默认字符集

二.修改httpd默认的字符集

1>.查看默认的httpd字符集

[root@node101.yinzhengjie.org.cn ~]# egrep -v "^ *#|^$" /etc/httpd/conf/httpd.conf | grep AddDefaultCharset           #中文字符集:GBK, GB2312, GB18030,不过推荐使用默认的UTF-
AddDefaultCharset UTF-
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# curl -I http://127.0.0.1/
HTTP/1.1 OK
Date: Sun, Dec :: GMT
Server: Apache/2.4. (CentOS)
Last-Modified: Sat, Dec :: GMT
ETag: "25-599131e54e9d8"
Accept-Ranges: bytes
Content-Length:
Content-Type: text/html; charset=UTF- [root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#

2>.修改默认的httpd字符集为GB2312

[root@node101.yinzhengjie.org.cn ~]# curl -I http://127.0.0.1/
HTTP/1.1 OK
Date: Sun, Dec :: GMT
Server: Apache/2.4. (CentOS)
Last-Modified: Sat, Dec :: GMT
ETag: "25-599131e54e9d8"
Accept-Ranges: bytes
Content-Length:
Content-Type: text/html; charset=UTF-8 [root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# egrep -v "^ *#|^$" /etc/httpd/conf/httpd.conf | grep AddDefaultCharset
AddDefaultCharset UTF-
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# cat /etc/httpd/conf.d/charset.conf
AddDefaultCharset GB2312
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# egrep -v "^ *#|^$" /etc/httpd/conf/httpd.conf | grep ServerRoot
ServerRoot "/etc/httpd"
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# egrep -v "^ *#|^$" /etc/httpd/conf/httpd.conf | grep IncludeOptional
IncludeOptional conf.d/*.conf
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# egrep -v "^ *#|^$" /etc/httpd/conf/httpd.conf | grep AddDefaultCharset
AddDefaultCharset UTF-8
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# cat /etc/httpd/conf.d/charset.conf        #尽管主配置文件默认定义的是UTF8,但咱们在子配置文件中显式定义的编码依旧是优先生效的~
AddDefaultCharset GB2312
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# httpd -t
Syntax OK
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# systemctl restart httpd
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# curl -I http://127.0.0.1/
HTTP/1.1 200 OK
Date: Sun, 08 Dec 2019 21:32:00 GMT
Server: Apache/2.4.6 (CentOS)
Last-Modified: Sat, 07 Dec 2019 01:31:15 GMT
ETag: "25-599131e54e9d8"
Accept-Ranges: bytes
Content-Length: 37
Content-Type: text/html; charset=GB2312 [root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
上一篇:Httpd服务入门知识-Httpd服务常见配置案例之Apache的工作做状态status页面


下一篇:Windows漏洞:MS08-067远程代码执行漏洞复现及深度防御