如何启用 Keep Alive Apache

[ad_1]

Keep Alive 标头或 HTTP 持久连接通过对多个 HTTP 请求使用单个 TCP 连接来提高网站速度和性能。 因此,建议为您的网站启用 Keep Alive。 以下是启用 Keep Alive 的方法 Apache 在 CentOS/Ubuntu 中。

如何启用 Keep Alive Apache

默认情况下,Keep Alive 在 Apache 网络服务器。 以下是启用 Keep Alive 的方法 Apache.

保持活力有什么作用?

通常,任何服务器包括 Apache 为每个请求创建一个新的 TCP 连接。 这需要每次都进行身份验证和多次切换。 由于每个请求的页面都会发送多个请求,这可能会花费很多时间,尤其是对于许多并发用户。 如果您启用 活着 标题输入 Apache web 服务器,它将在第一次创建 TCP 连接,然后使用相同的 TCP 连接传输所有未来的请求,只要该人正在使用您的站点。 这通过节省大量时间来提高网站速度和性能。

1. 打开 Apache 配置文件

打开终端并运行以下命令打开 Apache 服务器配置文件。

CentOS /Fedora:

$ sudo vi /etc/httpd/conf/httpd.conf

Ubuntu/Debian:

$ sudo vi /etc/apache2/apache2.conf

如果要在 WordPress CPanel 中启用 Keep Alive,则必须使用 .htaccess 文件启用 Keep Alive。 在这种情况下,请在 /www/var/html/.htaccess 打开您的 .htaccess 文件。 如果它不存在,请在那里创建一个文件名为 .htaccess 的新空白文件。

奖励阅读:如何更改端口号 Apache

2.启用Keep Alive Apache

根据您的要求添加以下行。 在某些情况下,它们可能会在开头使用 # 符号进行注释。 只需将其删除即可启用这些设置。 有 3 个 Keep Alive 设置 Apache – KeepAlive、MaxKeepAliveRequests、KeepAliveTimeout

# KeepAlive: Enable/disable persistent connections
KeepAlive On


# MaxKeepAliveRequests: How many requests to allow during a persistent connection. 
# You can set it 0 for unlimited requests, but it is not recommended.
MaxKeepAliveRequests 100


# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection. Default is 5 seconds
KeepAliveTimeout 15

奖励阅读:如何从中删除服务器名称 Apache 回复

3.重启 Apache 服务器

重新启动服务器以启用 Keep Alive Apache.

$ sudo systemctl restart apache2 #SystemD
$ sudo service apache2 restart #SysVInit

4. 如何知道是否启用了 Keep-Alive

您是否想知道,“如何知道 Keep Alive 是否已启用并正常工作?”。 有许多 在线工具 您可以在其中输入您的网站 URL,他们会告诉您是否启用了 Keep Alive。

就是这样! 现在 Apache 为所有用户保持活跃的 TCP 连接并加速您的网站。

就是这样! 现在 Apache 为所有用户保持活跃的 TCP 连接并加速您的网站。 顺便说一句,如果您想创建图表和仪表板来监控您的业务或网站,您可以尝试 CodePre。 我们提供 14 天的免费试用。

[ad_2]

Related Posts