• 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 ~]# 
  • 相关阅读:
    Java Socket通信实现私聊、群聊
    一套简单的web即时通讯——第二版
    一套简单的web即时通讯——第一版
    前后端API交互数据加密——AES与RSA混合加密完整实例
    跨境电商ERP中的自动化 3.平台订单自动发货
    跨境电商ERP中的自动化 2.平台商品和本地单品自动绑定
    跨境电商ERP中的自动化 1.平台订单自动同步至本地
    小特工具箱3.0版发布 春节优惠价99元/套
    河南农信移动支付解析
    win10 chrome 百分浏览器 centbrowser 收藏夹栏字体突然变小
  • 原文地址:https://www.cnblogs.com/yinzhengjie/p/12004555.html
Copyright © 2020-2023  润新知