Httpd服务入门知识-Httpd服务常见配置案例之设定默认字符集
Httpd服务入门知识-Httpd服务常见配置案例之设定默认字符集
作者:尹正杰
版权声明:原创作品,谢绝转载!否则将追究法律责任。
一.查看生产环境中使用的字符集案例
1>.查看腾讯设置的默认字符集
2>.查看京东设置的默认字符集
二.修改httpd默认的字符集
1>.查看默认的httpd字符集
[root@node101.yinzhengjie.org.cn ~]# egrep -v "^ *#|^$" /etc/httpd/conf/httpd.conf | grep AddDefaultCharset #中文字符集:GBK, GB2312, GB18030,不过推荐使用默认的UTF-8 AddDefaultCharset UTF-8 [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:27:39 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=UTF-8 [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 200 OK Date: Sun, 08 Dec 2019 21:27:39 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=UTF-8 [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 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 ~]#
本文来自博客园,作者:尹正杰,转载请注明原文链接:https://www.cnblogs.com/yinzhengjie/p/12004555.html,个人微信: "JasonYin2020"(添加时请备注来源及意图备注,有偿付费)
当你的才华还撑不起你的野心的时候,你就应该静下心来学习。当你的能力还驾驭不了你的目标的时候,你就应该沉下心来历练。问问自己,想要怎样的人生。