zoukankan      html  css  js  c++  java
  • Httpd服务入门知识-Httpd服务常见配置案例之配置持久连接

            Httpd服务入门知识-Httpd服务常见配置案例之配置持久连接

                                            作者:尹正杰

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

     

    一.查看默认的持久连接时间

    [root@node101.yinzhengjie.org.cn ~]# egrep -v "^ *#|^$" /etc/httpd/conf/httpd.conf  
    ServerRoot "/etc/httpd"
    Listen 80
    Include conf.modules.d/*.conf
    User apache
    Group apache
    ServerAdmin root@localhost
    <Directory />
        AllowOverride none
        Require all denied
    </Directory>
    DocumentRoot "/var/www/html"
    <Directory "/var/www">
        AllowOverride None
        Require all granted
    </Directory>
    <Directory "/var/www/html">
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
    </Directory>
    <IfModule dir_module>
        DirectoryIndex index.html
    </IfModule>
    <Files ".ht*">
        Require all denied
    </Files>
    ErrorLog "logs/error_log"
    LogLevel warn
    <IfModule log_config_module>
        LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"" combined
        LogFormat "%h %l %u %t "%r" %>s %b" common
        <IfModule logio_module>
          LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i" %I %O" combinedio
        </IfModule>
        CustomLog "logs/access_log" combined
    </IfModule>
    <IfModule alias_module>
        ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
    </IfModule>
    <Directory "/var/www/cgi-bin">
        AllowOverride None
        Options None
        Require all granted
    </Directory>
    <IfModule mime_module>
        TypesConfig /etc/mime.types
        AddType application/x-compress .Z
        AddType application/x-gzip .gz .tgz
        AddType text/html .shtml
        AddOutputFilter INCLUDES .shtml
    </IfModule>
    AddDefaultCharset UTF-8
    <IfModule mime_magic_module>
        MIMEMagicFile conf/magic
    </IfModule>
    EnableSendfile on
    IncludeOptional conf.d/*.conf
    [root@node101.yinzhengjie.org.cn ~]# 
    [root@node101.yinzhengjie.org.cn ~]# egrep -v "^ *#|^$" /etc/httpd/conf/httpd.conf        #查看默认的主配置文件,该配置文件并没有显示指定持久连接配置参数,官方文档中却指出了默认是开启的,如下图所示。
    Persistent Connection:
      连接建立,每个资源获取完成后不会断开连接,而是继续等待其它的请求完成,如下图所示,默认开启持久连接。
    断开条件:
      时间限制:以秒为单位, 默认5s,httpd
    -2.4支持毫秒级,如果指定为毫秒值需要显式指定时间单位,如"KeepAliveTimeout 300ms"。
    副作用:
      对并发访问量大的服务器,持久连接会使有些请求得不到响应
    折中方案:
      使用较短的持久连接时间

    二..自定义持久连接时间

    1>.自定义配置文件

    [root@node101.yinzhengjie.org.cn ~]# cat /etc/httpd/conf.d/keepalive.conf
    KeepAlive On
    KeepAliveTimeout 20
    [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 reload httpd
    [root@node101.yinzhengjie.org.cn ~]# 
    [root@node101.yinzhengjie.org.cn ~]# ss -ntl
    State       Recv-Q Send-Q        Local Address:Port                       Peer Address:Port              
    LISTEN      0      128                       *:80                                    *:*                  
    LISTEN      0      128                       *:22                                    *:*                  
    LISTEN      0      128                      :::22                                   :::*                  
    [root@node101.yinzhengjie.org.cn ~]# 
    [root@node101.yinzhengjie.org.cn ~]# 

    2>.测试

    [root@node101.yinzhengjie.org.cn ~]# telnet 172.30.1.101 80      #注意,连接成功后,若在咱们规定的20秒内没有和httpd服务端发送消息,则服务端的持久连接自动就断开啦~
    Trying 172.30.1.101...
    Connected to 172.30.1.101.
    Escape character is '^]'.
    Connection closed by foreign host.
    [root@node101.yinzhengjie.org.cn ~]# 
    [root@node101.yinzhengjie.org.cn ~]# telnet 172.30.1.101 80
    Trying 172.30.1.101...
    Connected to 172.30.1.101.
    Escape character is '^]'.
    GET /index.html HTTP/1.1    #此处我们使用GET方法,请求的资源为"/index.html",指定HTTP协议的版本号为"HTTP/1.1"
    HOST: 1.1.1.1           #此处配置的是headers信息中的HOST信息,并没有配置其它参数,后面紧接着是一个换行符
                       #紧接着我们需要连续输入2个换行符,下面的请求方式一样。
    HTTP/1.1 200 OK
    Date: Sat, 07 Dec 2019 07:15:35 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
    
    https://www.cnblogs.com/yinzhengjie/
    GET /info.html HTTP/1.1
    HOST: 2.2.2.2
    
    HTTP/1.1 200 OK
    Date: Sat, 07 Dec 2019 07:15:54 GMT
    Server: Apache/2.4.6 (CentOS)
    Last-Modified: Sat, 07 Dec 2019 07:11:56 GMT
    ETag: "1f-59917e0ae7f18"
    Accept-Ranges: bytes
    Content-Length: 31
    Content-Type: text/html; charset=UTF-8
    
    <h1>尹正杰到此一游</h1>
    GET /student.html HTTP/1.1
    HOST: 3.3.3.3
    
    HTTP/1.1 200 OK
    Date: Sat, 07 Dec 2019 07:16:22 GMT
    Server: Apache/2.4.6 (CentOS)
    Last-Modified: Sat, 07 Dec 2019 07:12:28 GMT
    ETag: "13-59917e2931d98"
    Accept-Ranges: bytes
    Content-Length: 19
    Content-Type: text/html; charset=UTF-8
    
    <h1>尹正杰</h1>
    Connection closed by foreign host.
    [root@node101.yinzhengjie.org.cn ~]# 
  • 相关阅读:
    Java基础
    第11章 处理概括关系
    第10章 简化函数调用
    第9章 简化条件表达式
    第8章 重新组织数据(暂略)
    第7章 在对象之间搬移特性
    第6章 重新组织函数
    【剑指offer】57
    【每日一题-leetcode】45.跳跃游戏 ||
    【左神算法】随机+荷兰国旗优化版快排
  • 原文地址:https://www.cnblogs.com/yinzhengjie/p/12000655.html
Copyright © 2011-2022 走看看