Apache开启KeepAlive选项

修改方法:

关于KeepAlive的选项在/private/etc/apache2/extra/httpd-default.conf中已经有了配置,但是默认来说没有引入到httpd.conf中,因此在httpd.conf找到httpd-default.conf的引用并去掉注释即可。

步骤:

1 编辑文件

$ sudo vim /private/etc/apache2/default.conf 

2 httpd文件路径:/private/etc/apache2/httpd.conf,修改为如下:

# Various default settings
Include /private/etc/apache2/extra/httpd-default.conf

3 校验正确性并重启Apache

$ sudo apachectl configtest
$ sudo apachectl restart

参数介绍

/private/etc/apache2/extra/httpd-default.conf中,我用到的参数主要如下:

1 KeepAlive:是否开启KeepAlive

2 MaxKeepAliveRequests:在一个长连接(同一个socket)中,最大能接收的请求数量,如果设置为0则代表无限。我配置的为默认的100,可以看到如果是在这一个连接中发送的第二个请求,则收到的内容则包含如下:其中Keep-Alive的max就是还可以在这个连接中继续发送的请求的数量。

HTTP/1.1 200 OK
Date: Tue, 21 Aug 2018 06:41:05 GMT
Server: Apache/2.4.33 (Unix) PHP/7.1.16
Last-Modified: Mon, 04 Dec 2017 09:21:27 GMT
ETag: "26e-55f803e2ad3c0"
Accept-Ranges: bytes
Content-Length: 622
Keep-Alive: timeout=5, max=99
Connection: Keep-Alive
Content-Type: text/html

3 KeepAliveTimeout:两次请求之间的超时时间,我的理解是,如果在这个时间之后服务器还没有收到第二个请求,则会关闭连接。

关于KeepAlive相关含义参考:https://www.cnblogs.com/fnng/archive/2012/11/25/2787755.html

猜你喜欢

转载自blog.csdn.net/lllkey/article/details/81906941