Server Tuning

Table of Contents

OS Optimization

Default SHM Directory

Connection Tuning

Max Connections | 最大SSL连接数 | 连接超时时长 | 最大持续连接请求数 | 智能持续连接 | 持续连接超时时长 | 发送缓冲区大小 | 接收缓冲区大小

请求/响应调整

最大请求URL长度 | 最大请求头大小 | 最大请求主内容大小 | 动态回应报头最大大小 | 动态回应主内容最大大小

Static File Delivery Optimization

最大小文件缓存 | 小文件缓存总大小 | 最大MMAP文件大小 | 总MMAP缓存大小 | 使用sendfile() | 文件ETag

GZIP/Brotli Compression

启用压缩 | 压缩类型 | 启用动态压缩 | 压缩级别(动态内容) | Brotli Compression Level (Dynamic Content) | 自动更新静态文件 | 压缩级别(静态内容) | Brotli Compression Level (Static File) | 静态GZIP缓存目录 | 静态文件最大尺寸 | 静态文件最小尺寸

SSL Global Setting

SSL Strong DH Key | Enable Multiple SSL Certificates | Enable Session Cache | Session Cache Size (bytes) | Session Cache Timeout (secs) | Enable Session Tickets | SSL Session Ticket Lifetime (secs) | SSL Session Ticket Key File

QUIC

Enable QUIC | QUIC SHM Directory | QUIC Versions | Congestion Control | Connection Flow Control Window | Max Connection Flow Control Window | Stream Flow Control Window | Max Stream Flow Control Window | Max Concurrent Streams Per Connection | Handshake Timeout | Idle Timeout

Default SHM Directory

Description

Changes shared memory's default directory to the specified path. If the directory does not exist, it will be created. All SHM data will be stored in this directory unless otherwise specified.

Syntax

Path

Max Connections

Description

Specifies the maximum number of concurrent connections that the server can accept. This includes both plain TCP connections and SSL connections. Once the maximum concurrent connections limit is reached, the server will close Keep-Alive connections when they complete active requests.

Syntax

无符号整数

Tips

When the server is started by "root" user, the server will try to adjust the per-process file descriptor limits automatically, however, if this fails, you may need to increase this limit manually.

最大SSL连接数

Description

指定服务器接受的并发SSL连接的最大数量。 由于总的并发SSL和非SSL连接不能超过Max Connections规定的限额, 允许的并发SSL连接的实际数量必须低于此限制。

Syntax

无符号整数

连接超时时长

Description

指定在处理一个请求时所允许的最长连接闲置时间。 如果它在此期间一直闲置,例如没有I/O活动,连接将被关闭。

Syntax

无符号整数

Tips

[安全建议] 将值设置得尽可能低,在可能的拒绝服务攻击中,这可以帮助释放无效连接所占用的连接数。

See Also

持续连接超时时长

最大持续连接请求数

Description

指定通过持续连接(持久)会话处理的请求的最大数量。一旦达 到此限制,连接将被关闭。您也可以为每个虚拟主机单独设置限制。

Syntax

无符号整数

Tips

[性能建议] 设置为合理的较高的值。值为“1”或“0”时将禁用持续连接。

See Also

Virtual Host 最大Keep-Alive请求数

智能持续连接

Description

指定是否启用智能持续连接。此选项只在最大持续连接请求数的值大于1 时有效。启用之后,您还可以在虚拟主机级别启用或禁用它。智能持久连接将只为 JavaScript、CSS样式表和图像文件请求建立持续连接。对于HTML页面,连接 不会被保持活跃。这有助于更高效地服务更多用户。通常包含多个图像和脚本的 网页将在初次请求之后被浏览器缓存。 通过一个持续连接来发送那些非HTML静态文件,同时通过另一非持续连接发送 text/html文件的做法更为高效。这种方法将减少闲置连接,进而提高处理并发请 求和更多用户的能力。

Syntax

布尔值

Tips

[性能建议] 为高负载网站启用该功能。

See Also

Virtual Host 智能Keep-Alive

持续连接超时时长

Description

指定持续连接请求的最长闲置时间。 如果在这段时间内没有接收到新的请求,该连接将被关闭。

Syntax

无符号整数

Tips

[安全和性能建议] 我们建议您将值设置得刚好足够处理单个页面 视图的所有请求。没有必要延长持续连接时间。较小的值可以减少闲置 连接,提高能力,以服务更多的用户,并防范拒绝服务攻击。2-5秒 对大多数应用是合理范围。Litespeed在非持续连接环境是非常高效的。

发送缓冲区大小

Description

每个TCP套接字的发送缓冲区的大小。设定值为0使用 操作系统默认的缓冲区大小。65535是允许的最大缓冲区大小。

Syntax

无符号整数

Tips

[性能建议] 如果您的网站服务大量的静态文件,增加发送缓冲区 大小来提高性能。

接收缓冲区大小

Description

每个TCP套接字的接收缓冲区的大小。设定值为0使用 操作系统默认的缓冲区大小。65535是允许的最大缓冲区大小。

Syntax

无符号整数

Tips

[性能建议] 处理大载荷入站请求,如文件上传时,大的接收缓冲区会提高性能。

最大请求URL长度

Description

指定请求URL的最大大小。URL是一个纯文本的地址,包含查询字符串来请求服务器上的资源。 8192字节是硬限制。

Syntax

无符号整数

Tips

[安全和性能建议] 将其设置合理的低值来以减少内存使用 并帮助识别虚假请求和拒绝服务攻击。
对大多数网站2000-3000已经足够大,除非使用HTTP GET而不是POST来提交大型的查询字符串。

最大请求头大小

Description

指定请求URL中包含的HTTP请求头最大值。 硬限制为16380字节。

Syntax

无符号整数

Tips

[安全和性能建议] 设置合理的低值来减少内存的使用并帮助识别虚假请求和拒绝服务攻击。
对于大多数网站来说4000-8000已经足够大。

最大请求主内容大小

Description

指定HTTP请求主内容最大尺寸。对于32位操作系统, 硬限制为2GB。对于64位操作系统,几乎是无限的。

Syntax

无符号整数

Tips

[安全建议] 为了防止拒绝服务攻击,尽量将限制值设定到实际需求的大小。 交换空间的剩余空间必须比这个限制值大。

动态回应报头最大大小

Description

指定动态回应的最大报头大小。硬限制为8KB

Syntax

无符号整数

Tips

[可靠性和性能建议] 设置一个合理的低值以帮助识别外部应用程序产生的 坏的动态回应。

动态回应主内容最大大小

Description

指定动态回应的最大主内容尺寸。硬限制是2047MB

Syntax

无符号整数

Tips

[可靠性和性能建议] 设置一个合理的低值以帮助识别坏的响应。恶意脚本经常包含 无限循环而导致大尺寸回应。

最大小文件缓存

Description

指定预分配内存缓冲区中缓存的静态文件最大尺寸。静态文件 可以用四种不同的方式服务:内存缓存、内存映射缓存、直接读写和 sendfile()。 尺寸小于最大小文件缓存的文件将使用内存缓存服务。尺寸大于该限制、但小于 最大MMAP文件大小的文件,将使用内存映射缓存服务。 尺寸大于最大MMAP文件大小的文件将通过直接读写或sendfile() 服务。使用内存缓存服务小于4K的文件是最佳做法。

Syntax

无符号整数

小文件缓存总大小

Description

指定分配用于缓存/服务小静态文件的总内存。

Syntax

无符号整数

最大MMAP文件大小

Description

指定使用内存映射(MMAP)的最大静态文件大小。 静态文件可以用四种不同的方式服务:内存缓存、内存映射缓存、直接读写和 sendfile()。 尺寸小于最大小文件缓存的文件将使用内存缓存服务。尺寸大于该限制、但小于 最大MMAP文件大小的文件,将使用内存映射缓存服务。 尺寸大于最大MMAP文件大小的文件将通过直接读写或sendfile() 服务。 由于服务器有一个32位的地址空间(2GB),不建议使用内存映射非常大的文件。

Syntax

无符号整数

总MMAP缓存大小

Description

指定分配用于缓存/服务中等大小静态文件的总内存。

Syntax

无符号整数

使用sendfile()

Description

指定是否使用sendfile()系统调用来服务静态文件。静态文件 可以用四种不同的方式服务:内存缓存、内存映射缓存、直接读写和 sendfile()。 尺寸小于最大小文件缓存的文件将使用内存缓存服务。尺寸大于该限制、但小于 最大MMAP文件大小的文件,将使用内存映射缓存服务。 尺寸大于最大MMAP文件大小的文件将通过直接读写或sendfile() 服务。Sendfile()是一个“零拷贝”系统调用,可在服务非常大的 文件时大大减少CPU的使用率。Sendfile()需要一个优化的网卡内核驱动, 因此可能不适合某些小厂商的网络适配器。

Syntax

布尔值

文件ETag

Description

指定是否使用一个文件的索引节点、最后修改时间和大小属性 生成静态文件的ETag HTTP响应头。 所有这三个属性是默认启用的。 如果您打算使用镜像服务器服务相同的文件,您应该不勾选索引节点。 否则,为同一个文件生成的ETag在不同的服务器上是不同的。

Syntax

复选框

启用压缩

Description

控制静态或动态HTTP回应的GZIP压缩。

Syntax

布尔值

Tips

[性能建议] 开启该功能可以节省网络带宽。 针对基于文本的回应如html、css和javascript文件最有效果,一般可以压缩到原文件大小的一半大小。

压缩类型

Description

指定允许哪些MIME类型进行压缩。

Syntax

以逗号分隔的MIME类型列表。通配符“*”和 否定符号“!”是允许的,如text/*, !text/js。

Example

If you want to compress text/* but not text/css, you can have a rule like text/*, !text/css. "!" will exclude that MIME type.

Tips

[性能建议] 只允许特定类型进行GZIP压缩。 二进制文件如gif/png/jpeg图片文件及flash文件无法从压缩中获益。

启用动态压缩

Description

控制动态HTTP回应的GZIP压缩。 启用压缩必须设置为Yes来开启动态GZIP压缩。

Syntax

布尔值

Tips

[性能建议] 压缩动态回应将增加CPU和内存的使用,但可以节省网络带宽。

压缩级别(动态内容)

Description

指定压动态态内容的级别。 范围从1 (最低)到9 (最高)。默认值是2

Syntax

1到9之间的数。

Tips

[性能建议] 更高的压缩级别将消耗更多的内存和CPU资源。 如果您的机器有额外的资源您可以设置更高的级别。 级别9与级别6没有太大的区别,但是级别9会占用多得多的CPU资源。

Brotli Compression Level (Dynamic Content)

Description

Controls the level of Brotli compression applied to dynamic responses. Ranges from 0 (OFF) to 6 (highest).

This setting will only take effect when 启用压缩 is enabled.

Default value: 2

Syntax

Number between 0 and 6.

自动更新静态文件

Description

指定是否由LiteSpeed自动创建/更新可压缩静态文件的GZIP压缩版本。 如果设置为Yes,当请求文件MIME属于压缩类型时, LiteSpeed会根据压缩的文件时间戳来创建/更新文件的压缩版本。 压缩的文档会创建在静态GZIP缓存目录目录下。 文件名称根据原文件的MD5散列创建。

Syntax

布尔值

压缩级别(静态内容)

Description

指定压缩静态内容的级别。 范围从1 (最低)到9 (最高)。默认值是6

Syntax

1到9之间的数。

Brotli Compression Level (Static File)

Description

Specifies the level of Brotli compression applied to static files. Ranges from 1 (lowest) to 11 (highest).

This setting will only take effect when 启用压缩 and 自动更新静态文件 are enabled.

Default value: 5

Syntax

Number between 1 and 11.

Tips

Save network bandwidth. Text-based responses such as html, css, and javascript files benefit the most and on average can be compressed to half of their original size.

静态GZIP缓存目录

Description

指定目录路径来存储静态内容的压缩文件。默认是交换目录

Syntax

目录路径

静态文件最大尺寸

Description

指定LiteSpeed可以自动创建压缩文件的静态文件最大尺寸。

Syntax

不小于1K的字节数。

Tips

[性能建议] 不建议使用LiteSpeed创建/更新较大文件的压缩文件。 压缩操作会占用整个服务器进程并且在压缩结束前新请求都无法被处理。

静态文件最小尺寸

Description

指定LiteSpeed创建相应压缩文件的静态文件最小尺寸。

Syntax

不小于200的字节数。

Tips

因为流量节省可以忽略不计,所以压缩非常小的文件是没有必要的。

SSL Strong DH Key

Description

Specifies whether to use 2048 or 1024 bit DH keys for SSL handshakes. If set to "Yes", 2048 bit DH keys will be used for 2048 bit SSL keys and certificates. 1024 bit DH keys will still be used in other situations. Default is "Yes".

Earlier versions of Java do not support DH key size higher than 1024 bits. If Java client compatibility is required, this should be set to "No".

Syntax

radio

Enable Multiple SSL Certificates

Description

Allows listeners/vhosts to set multiple SSL certificates. If multiple certificates are enabled, the certificates/keys are expected to follow a naming scheme. If the cert is named server.crt, other possible cert names are server.crt.rsa, server.crt.dsa, server.crt.ecc. If "Not Set", defaults to "No".

Syntax

Select from radio box

Enable Session Cache

Description

Enables session ID caching using OpenSSL's default setting. Server-level setting must be set to "Yes" for Virtual Host setting to take effect.

Default values:
Server-level: Yes
VH-Level: Yes

Syntax

Select from radio box

Session Cache Size (bytes)

Description

Sets the maximum number of SSL session IDs to store in the cache. Default is 1,000,000.

Syntax

Integer number

Session Cache Timeout (secs)

Description

This value determines how long a session ID will be valid within the cache before renegotiation is required. Default is 3,600.

Syntax

Integer number

Enable Session Tickets

Description

Enables session tickets using OpenSSL's default session ticket setting. Server-level setting must be set to "Yes" for Virtual Host setting to take effect.

Default values:
Server-level: Yes
VH-Level: Yes

Syntax

Select from radio box

SSL Session Ticket Lifetime (secs)

Description

This value determines how long a session ticket will be valid before a renegotiation is required. Default is 3,600.

Syntax

Integer number

SSL Session Ticket Key File

Description

Allows the SSL Ticket Key to be created/maintained by an administrator. The file must be 48 bytes long. If this option is left empty, the load balancer will generate and rotate its own set of keys.

IMPORTANT: To maintain forward secrecy, it is strongly recommended to change the key every SSL Session Ticket Lifetime seconds. If this cannot be done, it is recommended to leave this field empty.

Syntax

Path

Enable QUIC

Description

Enables the QUIC network protocol server wide. Default value is Yes.

Syntax

Select from radio box

Tips

When this setting is set to Yes, QUIC can still be disabled at the listener level through the Allow QUIC setting, or at the virtual host level through the Enable QUIC setting.

QUIC SHM Directory

Description

Specifies the directory used to save QUIC data to shared memory.

By default, the server's default SHM directory, /dev/shm, will be used.

Syntax

Path

Tips

A RAM based partition, such as /dev/shm, is recommended.

QUIC Versions

Description

A list of enabled QUIC versions. This setting should only be used to limit QUIC support to the versions listed and is best left blank.

Syntax

Comma-separated list

Example

Q035, Q039

Tips

It is recommended to leave this setting blank to have the the best configuration applied automatically.

Congestion Control

Description

The congestion control algorithm used. This can be set manually or left up to the QUIC library in use by selecting the "Default" option.

Default value: Default

Syntax

Select from drop down list

Connection Flow Control Window

Description

The initial size of the buffer allocated for a QUIC connection. Default value is 1.5M.

Syntax

Number between 64K and 512M

Tips

A larger window size will use more memory.

Max Connection Flow Control Window

Description

Specifies the maximum size that a connection flow control window buffer is allowed to reach due to window auto-tuning.

Default value is 0, which means that the value of Connection Flow Control Window is used and no auto-tuning is performed.

Syntax

0 or a number between 64K and 512M

Tips

A larger window size will use more memory.

Stream Flow Control Window

Description

The initial amount of data a QUIC connection is willing to receive per stream. Default value is 1M.

Syntax

Number between 64K and 128M

Tips

A larger window size will use more memory.

Max Stream Flow Control Window

Description

Specifies the maximum size that a stream flow control window is allowed to reach due to window auto-tuning.

Default value is 0, which means that the value of Stream Flow Control Window is used and no auto-tuning is performed.

Syntax

0 or a number between 64K and 128M

Tips

A larger window size will use more memory.

Max Concurrent Streams Per Connection

Description

The maximum number of concurrent streams allowed per QUIC connection. Default value is 100.

Syntax

Integer number between 10 and 1000

Handshake Timeout

Description

The time in seconds a new QUIC connection is given to complete its handshake, after which the connection is aborted. Default value is 10.

Syntax

Integer number between 1 and 15

Idle Timeout

Description

The time in seconds after which an idle QUIC connection will be closed. Default value is 30.

Syntax

Integer number between 10 and 30