mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-10 17:26:38 +08:00
迁移配置表
This commit is contained in:
@@ -1,80 +1,80 @@
|
||||
export type PerformanceFields = {
|
||||
OpenRestyDefaultServerReturnStatus: string
|
||||
OpenRestyWorkerProcesses: string
|
||||
OpenRestyWorkerConnections: string
|
||||
OpenRestyWorkerRlimitNofile: string
|
||||
OpenRestyEventsUse: string
|
||||
OpenRestyEventsMultiAcceptEnabled: boolean
|
||||
OpenRestyKeepaliveTimeout: string
|
||||
OpenRestyKeepaliveRequests: string
|
||||
OpenRestyClientHeaderTimeout: string
|
||||
OpenRestyClientBodyTimeout: string
|
||||
OpenRestyClientMaxBodySize: string
|
||||
OpenRestyLargeClientHeaderBuffers: string
|
||||
OpenRestySendTimeout: string
|
||||
OpenRestyProxyConnectTimeout: string
|
||||
OpenRestyProxySendTimeout: string
|
||||
OpenRestyProxyReadTimeout: string
|
||||
OpenRestyWebsocketEnabled: boolean
|
||||
OpenRestyHTTP3Enabled: boolean
|
||||
OpenRestyProxyRequestBufferingEnabled: boolean
|
||||
OpenRestyProxyBufferingEnabled: boolean
|
||||
OpenRestyProxyBuffers: string
|
||||
OpenRestyProxyBufferSize: string
|
||||
OpenRestyProxyBusyBuffersSize: string
|
||||
OpenRestyGzipEnabled: boolean
|
||||
OpenRestyGzipMinLength: string
|
||||
OpenRestyGzipCompLevel: string
|
||||
OpenRestyCacheEnabled: boolean
|
||||
OpenRestyCachePath: string
|
||||
OpenRestyCacheLevels: string
|
||||
OpenRestyCacheInactive: string
|
||||
OpenRestyCacheMaxSize: string
|
||||
OpenRestyCacheKeyTemplate: string
|
||||
OpenRestyCacheLockEnabled: boolean
|
||||
OpenRestyCacheLockTimeout: string
|
||||
OpenRestyCacheUseStale: string
|
||||
OpenRestyResolvers: string
|
||||
openresty_default_server_return_status: string
|
||||
openresty_worker_processes: string
|
||||
openresty_worker_connections: string
|
||||
openresty_worker_rlimit_nofile: string
|
||||
openresty_events_use: string
|
||||
openresty_events_multi_accept_enabled: boolean
|
||||
openresty_keepalive_timeout: string
|
||||
openresty_keepalive_requests: string
|
||||
openresty_client_header_timeout: string
|
||||
openresty_client_body_timeout: string
|
||||
openresty_client_max_body_size: string
|
||||
openresty_large_client_header_buffers: string
|
||||
openresty_send_timeout: string
|
||||
openresty_proxy_connect_timeout: string
|
||||
openresty_proxy_send_timeout: string
|
||||
openresty_proxy_read_timeout: string
|
||||
openresty_websocket_enabled: boolean
|
||||
openresty_http3_enabled: boolean
|
||||
openresty_proxy_request_buffering_enabled: boolean
|
||||
openresty_proxy_buffering_enabled: boolean
|
||||
openresty_proxy_buffers: string
|
||||
openresty_proxy_buffer_size: string
|
||||
openresty_proxy_busy_buffers_size: string
|
||||
openresty_gzip_enabled: boolean
|
||||
openresty_gzip_min_length: string
|
||||
openresty_gzip_comp_level: string
|
||||
openresty_cache_enabled: boolean
|
||||
openresty_cache_path: string
|
||||
openresty_cache_levels: string
|
||||
openresty_cache_inactive: string
|
||||
openresty_cache_max_size: string
|
||||
openresty_cache_key_template: string
|
||||
openresty_cache_lock_enabled: boolean
|
||||
openresty_cache_lock_timeout: string
|
||||
openresty_cache_use_stale: string
|
||||
openresty_resolvers: string
|
||||
}
|
||||
|
||||
export const defaultPerformanceFields: PerformanceFields = {
|
||||
OpenRestyDefaultServerReturnStatus: "421",
|
||||
OpenRestyWorkerProcesses: "auto",
|
||||
OpenRestyWorkerConnections: "4096",
|
||||
OpenRestyWorkerRlimitNofile: "65535",
|
||||
OpenRestyEventsUse: "epoll",
|
||||
OpenRestyEventsMultiAcceptEnabled: true,
|
||||
OpenRestyKeepaliveTimeout: "20",
|
||||
OpenRestyKeepaliveRequests: "1000",
|
||||
OpenRestyClientHeaderTimeout: "15",
|
||||
OpenRestyClientBodyTimeout: "15",
|
||||
OpenRestyClientMaxBodySize: "64m",
|
||||
OpenRestyLargeClientHeaderBuffers: "4 16k",
|
||||
OpenRestySendTimeout: "30",
|
||||
OpenRestyProxyConnectTimeout: "3",
|
||||
OpenRestyProxySendTimeout: "60",
|
||||
OpenRestyProxyReadTimeout: "60",
|
||||
OpenRestyWebsocketEnabled: true,
|
||||
OpenRestyHTTP3Enabled: true,
|
||||
OpenRestyProxyRequestBufferingEnabled: false,
|
||||
OpenRestyProxyBufferingEnabled: true,
|
||||
OpenRestyProxyBuffers: "16 16k",
|
||||
OpenRestyProxyBufferSize: "8k",
|
||||
OpenRestyProxyBusyBuffersSize: "64k",
|
||||
OpenRestyGzipEnabled: true,
|
||||
OpenRestyGzipMinLength: "1024",
|
||||
OpenRestyGzipCompLevel: "5",
|
||||
OpenRestyCacheEnabled: false,
|
||||
OpenRestyCachePath: "",
|
||||
OpenRestyCacheLevels: "1:2",
|
||||
OpenRestyCacheInactive: "30m",
|
||||
OpenRestyCacheMaxSize: "1g",
|
||||
OpenRestyCacheKeyTemplate: "$scheme$host$request_uri",
|
||||
OpenRestyCacheLockEnabled: true,
|
||||
OpenRestyCacheLockTimeout: "5s",
|
||||
OpenRestyCacheUseStale:
|
||||
openresty_default_server_return_status: "421",
|
||||
openresty_worker_processes: "auto",
|
||||
openresty_worker_connections: "4096",
|
||||
openresty_worker_rlimit_nofile: "65535",
|
||||
openresty_events_use: "epoll",
|
||||
openresty_events_multi_accept_enabled: true,
|
||||
openresty_keepalive_timeout: "20",
|
||||
openresty_keepalive_requests: "1000",
|
||||
openresty_client_header_timeout: "15",
|
||||
openresty_client_body_timeout: "15",
|
||||
openresty_client_max_body_size: "64m",
|
||||
openresty_large_client_header_buffers: "4 16k",
|
||||
openresty_send_timeout: "30",
|
||||
openresty_proxy_connect_timeout: "3",
|
||||
openresty_proxy_send_timeout: "60",
|
||||
openresty_proxy_read_timeout: "60",
|
||||
openresty_websocket_enabled: true,
|
||||
openresty_http3_enabled: true,
|
||||
openresty_proxy_request_buffering_enabled: false,
|
||||
openresty_proxy_buffering_enabled: true,
|
||||
openresty_proxy_buffers: "16 16k",
|
||||
openresty_proxy_buffer_size: "8k",
|
||||
openresty_proxy_busy_buffers_size: "64k",
|
||||
openresty_gzip_enabled: true,
|
||||
openresty_gzip_min_length: "1024",
|
||||
openresty_gzip_comp_level: "5",
|
||||
openresty_cache_enabled: false,
|
||||
openresty_cache_path: "",
|
||||
openresty_cache_levels: "1:2",
|
||||
openresty_cache_inactive: "30m",
|
||||
openresty_cache_max_size: "1g",
|
||||
openresty_cache_key_template: "$scheme$host$request_uri",
|
||||
openresty_cache_lock_enabled: true,
|
||||
openresty_cache_lock_timeout: "5s",
|
||||
openresty_cache_use_stale:
|
||||
"error timeout updating http_500 http_502 http_503 http_504",
|
||||
OpenRestyResolvers: "",
|
||||
openresty_resolvers: "",
|
||||
}
|
||||
|
||||
export function optionsToMap(options: Array<{ key: string; value: string }>) {
|
||||
@@ -93,65 +93,65 @@ export function mapOptionsToFields(
|
||||
optionMap: Record<string, string>,
|
||||
): PerformanceFields {
|
||||
return {
|
||||
OpenRestyDefaultServerReturnStatus:
|
||||
optionMap.OpenRestyDefaultServerReturnStatus ?? "421",
|
||||
OpenRestyWorkerProcesses: optionMap.OpenRestyWorkerProcesses ?? "auto",
|
||||
OpenRestyWorkerConnections: optionMap.OpenRestyWorkerConnections ?? "4096",
|
||||
OpenRestyWorkerRlimitNofile:
|
||||
optionMap.OpenRestyWorkerRlimitNofile ?? "65535",
|
||||
OpenRestyEventsUse: optionMap.OpenRestyEventsUse ?? "epoll",
|
||||
OpenRestyEventsMultiAcceptEnabled: toBoolean(
|
||||
optionMap.OpenRestyEventsMultiAcceptEnabled,
|
||||
openresty_default_server_return_status:
|
||||
optionMap.openresty_default_server_return_status ?? "421",
|
||||
openresty_worker_processes: optionMap.openresty_worker_processes ?? "auto",
|
||||
openresty_worker_connections: optionMap.openresty_worker_connections ?? "4096",
|
||||
openresty_worker_rlimit_nofile:
|
||||
optionMap.openresty_worker_rlimit_nofile ?? "65535",
|
||||
openresty_events_use: optionMap.openresty_events_use ?? "epoll",
|
||||
openresty_events_multi_accept_enabled: toBoolean(
|
||||
optionMap.openresty_events_multi_accept_enabled,
|
||||
true,
|
||||
),
|
||||
OpenRestyKeepaliveTimeout: optionMap.OpenRestyKeepaliveTimeout ?? "20",
|
||||
OpenRestyKeepaliveRequests: optionMap.OpenRestyKeepaliveRequests ?? "1000",
|
||||
OpenRestyClientHeaderTimeout:
|
||||
optionMap.OpenRestyClientHeaderTimeout ?? "15",
|
||||
OpenRestyClientBodyTimeout: optionMap.OpenRestyClientBodyTimeout ?? "15",
|
||||
OpenRestyClientMaxBodySize: optionMap.OpenRestyClientMaxBodySize ?? "64m",
|
||||
OpenRestyLargeClientHeaderBuffers:
|
||||
optionMap.OpenRestyLargeClientHeaderBuffers ?? "4 16k",
|
||||
OpenRestySendTimeout: optionMap.OpenRestySendTimeout ?? "30",
|
||||
OpenRestyProxyConnectTimeout: optionMap.OpenRestyProxyConnectTimeout ?? "3",
|
||||
OpenRestyProxySendTimeout: optionMap.OpenRestyProxySendTimeout ?? "60",
|
||||
OpenRestyProxyReadTimeout: optionMap.OpenRestyProxyReadTimeout ?? "60",
|
||||
OpenRestyWebsocketEnabled: toBoolean(
|
||||
optionMap.OpenRestyWebsocketEnabled,
|
||||
openresty_keepalive_timeout: optionMap.openresty_keepalive_timeout ?? "20",
|
||||
openresty_keepalive_requests: optionMap.openresty_keepalive_requests ?? "1000",
|
||||
openresty_client_header_timeout:
|
||||
optionMap.openresty_client_header_timeout ?? "15",
|
||||
openresty_client_body_timeout: optionMap.openresty_client_body_timeout ?? "15",
|
||||
openresty_client_max_body_size: optionMap.openresty_client_max_body_size ?? "64m",
|
||||
openresty_large_client_header_buffers:
|
||||
optionMap.openresty_large_client_header_buffers ?? "4 16k",
|
||||
openresty_send_timeout: optionMap.openresty_send_timeout ?? "30",
|
||||
openresty_proxy_connect_timeout: optionMap.openresty_proxy_connect_timeout ?? "3",
|
||||
openresty_proxy_send_timeout: optionMap.openresty_proxy_send_timeout ?? "60",
|
||||
openresty_proxy_read_timeout: optionMap.openresty_proxy_read_timeout ?? "60",
|
||||
openresty_websocket_enabled: toBoolean(
|
||||
optionMap.openresty_websocket_enabled,
|
||||
true,
|
||||
),
|
||||
OpenRestyHTTP3Enabled: toBoolean(optionMap.OpenRestyHTTP3Enabled, false),
|
||||
OpenRestyProxyRequestBufferingEnabled: toBoolean(
|
||||
optionMap.OpenRestyProxyRequestBufferingEnabled,
|
||||
openresty_http3_enabled: toBoolean(optionMap.openresty_http3_enabled, false),
|
||||
openresty_proxy_request_buffering_enabled: toBoolean(
|
||||
optionMap.openresty_proxy_request_buffering_enabled,
|
||||
false,
|
||||
),
|
||||
OpenRestyProxyBufferingEnabled: toBoolean(
|
||||
optionMap.OpenRestyProxyBufferingEnabled,
|
||||
openresty_proxy_buffering_enabled: toBoolean(
|
||||
optionMap.openresty_proxy_buffering_enabled,
|
||||
true,
|
||||
),
|
||||
OpenRestyProxyBuffers: optionMap.OpenRestyProxyBuffers ?? "16 16k",
|
||||
OpenRestyProxyBufferSize: optionMap.OpenRestyProxyBufferSize ?? "8k",
|
||||
OpenRestyProxyBusyBuffersSize:
|
||||
optionMap.OpenRestyProxyBusyBuffersSize ?? "64k",
|
||||
OpenRestyGzipEnabled: toBoolean(optionMap.OpenRestyGzipEnabled, true),
|
||||
OpenRestyGzipMinLength: optionMap.OpenRestyGzipMinLength ?? "1024",
|
||||
OpenRestyGzipCompLevel: optionMap.OpenRestyGzipCompLevel ?? "5",
|
||||
OpenRestyCacheEnabled: toBoolean(optionMap.OpenRestyCacheEnabled, false),
|
||||
OpenRestyCachePath: optionMap.OpenRestyCachePath ?? "",
|
||||
OpenRestyCacheLevels: optionMap.OpenRestyCacheLevels ?? "1:2",
|
||||
OpenRestyCacheInactive: optionMap.OpenRestyCacheInactive ?? "30m",
|
||||
OpenRestyCacheMaxSize: optionMap.OpenRestyCacheMaxSize ?? "1g",
|
||||
OpenRestyCacheKeyTemplate:
|
||||
optionMap.OpenRestyCacheKeyTemplate ?? "$scheme$host$request_uri",
|
||||
OpenRestyCacheLockEnabled: toBoolean(
|
||||
optionMap.OpenRestyCacheLockEnabled,
|
||||
openresty_proxy_buffers: optionMap.openresty_proxy_buffers ?? "16 16k",
|
||||
openresty_proxy_buffer_size: optionMap.openresty_proxy_buffer_size ?? "8k",
|
||||
openresty_proxy_busy_buffers_size:
|
||||
optionMap.openresty_proxy_busy_buffers_size ?? "64k",
|
||||
openresty_gzip_enabled: toBoolean(optionMap.openresty_gzip_enabled, true),
|
||||
openresty_gzip_min_length: optionMap.openresty_gzip_min_length ?? "1024",
|
||||
openresty_gzip_comp_level: optionMap.openresty_gzip_comp_level ?? "5",
|
||||
openresty_cache_enabled: toBoolean(optionMap.openresty_cache_enabled, false),
|
||||
openresty_cache_path: optionMap.openresty_cache_path ?? "",
|
||||
openresty_cache_levels: optionMap.openresty_cache_levels ?? "1:2",
|
||||
openresty_cache_inactive: optionMap.openresty_cache_inactive ?? "30m",
|
||||
openresty_cache_max_size: optionMap.openresty_cache_max_size ?? "1g",
|
||||
openresty_cache_key_template:
|
||||
optionMap.openresty_cache_key_template ?? "$scheme$host$request_uri",
|
||||
openresty_cache_lock_enabled: toBoolean(
|
||||
optionMap.openresty_cache_lock_enabled,
|
||||
true,
|
||||
),
|
||||
OpenRestyCacheLockTimeout: optionMap.OpenRestyCacheLockTimeout ?? "5s",
|
||||
OpenRestyCacheUseStale:
|
||||
optionMap.OpenRestyCacheUseStale ??
|
||||
openresty_cache_lock_timeout: optionMap.openresty_cache_lock_timeout ?? "5s",
|
||||
openresty_cache_use_stale:
|
||||
optionMap.openresty_cache_use_stale ??
|
||||
"error timeout updating http_500 http_502 http_503 http_504",
|
||||
OpenRestyResolvers: optionMap.OpenRestyResolvers ?? "",
|
||||
openresty_resolvers: optionMap.openresty_resolvers ?? "",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,79 +178,79 @@ function isCacheLevelsValue(value: string) {
|
||||
|
||||
export function validateRuntimeFields(fields: PerformanceFields) {
|
||||
if (
|
||||
fields.OpenRestyWorkerProcesses !== "auto" &&
|
||||
!isPositiveInteger(fields.OpenRestyWorkerProcesses)
|
||||
fields.openresty_worker_processes !== "auto" &&
|
||||
!isPositiveInteger(fields.openresty_worker_processes)
|
||||
) {
|
||||
throw new Error("worker_processes 必须为 auto 或大于 0 的整数")
|
||||
}
|
||||
const integers = [
|
||||
fields.OpenRestyWorkerConnections,
|
||||
fields.OpenRestyWorkerRlimitNofile,
|
||||
fields.OpenRestyKeepaliveTimeout,
|
||||
fields.OpenRestyKeepaliveRequests,
|
||||
fields.OpenRestyClientHeaderTimeout,
|
||||
fields.OpenRestyClientBodyTimeout,
|
||||
fields.OpenRestySendTimeout,
|
||||
fields.openresty_worker_connections,
|
||||
fields.openresty_worker_rlimit_nofile,
|
||||
fields.openresty_keepalive_timeout,
|
||||
fields.openresty_keepalive_requests,
|
||||
fields.openresty_client_header_timeout,
|
||||
fields.openresty_client_body_timeout,
|
||||
fields.openresty_send_timeout,
|
||||
]
|
||||
if (integers.some((value) => !isPositiveInteger(value))) {
|
||||
throw new Error("超时与连接参数必须为大于 0 的整数")
|
||||
}
|
||||
const status = Number.parseInt(fields.OpenRestyDefaultServerReturnStatus, 10)
|
||||
const status = Number.parseInt(fields.openresty_default_server_return_status, 10)
|
||||
if (Number.isNaN(status) || status < 100 || status > 999) {
|
||||
throw new Error("空白页面返回状态码必须在 100 到 999 之间")
|
||||
}
|
||||
if (!isSizeValue(fields.OpenRestyClientMaxBodySize)) {
|
||||
if (!isSizeValue(fields.openresty_client_max_body_size)) {
|
||||
throw new Error("client_max_body_size 格式不合法")
|
||||
}
|
||||
if (!isProxyBuffersValue(fields.OpenRestyLargeClientHeaderBuffers)) {
|
||||
if (!isProxyBuffersValue(fields.openresty_large_client_header_buffers)) {
|
||||
throw new Error('large_client_header_buffers 格式必须类似 "4 16k"')
|
||||
}
|
||||
}
|
||||
|
||||
export function validateProxyFields(fields: PerformanceFields) {
|
||||
const timeouts = [
|
||||
fields.OpenRestyProxyConnectTimeout,
|
||||
fields.OpenRestyProxySendTimeout,
|
||||
fields.OpenRestyProxyReadTimeout,
|
||||
fields.openresty_proxy_connect_timeout,
|
||||
fields.openresty_proxy_send_timeout,
|
||||
fields.openresty_proxy_read_timeout,
|
||||
]
|
||||
if (timeouts.some((value) => !isPositiveInteger(value))) {
|
||||
throw new Error("代理超时参数必须为大于 0 的整数秒")
|
||||
}
|
||||
if (!isProxyBuffersValue(fields.OpenRestyProxyBuffers)) {
|
||||
if (!isProxyBuffersValue(fields.openresty_proxy_buffers)) {
|
||||
throw new Error('proxy_buffers 格式必须类似 "16 16k"')
|
||||
}
|
||||
if (
|
||||
!isSizeValue(fields.OpenRestyProxyBufferSize) ||
|
||||
!isSizeValue(fields.OpenRestyProxyBusyBuffersSize)
|
||||
!isSizeValue(fields.openresty_proxy_buffer_size) ||
|
||||
!isSizeValue(fields.openresty_proxy_busy_buffers_size)
|
||||
) {
|
||||
throw new Error("缓冲大小必须为整数或带 k/m/g 单位的值")
|
||||
}
|
||||
}
|
||||
|
||||
export function validateGzipFields(fields: PerformanceFields) {
|
||||
if (!isPositiveInteger(fields.OpenRestyGzipMinLength)) {
|
||||
if (!isPositiveInteger(fields.openresty_gzip_min_length)) {
|
||||
throw new Error("gzip_min_length 必须为大于 0 的整数")
|
||||
}
|
||||
const level = Number.parseInt(fields.OpenRestyGzipCompLevel, 10)
|
||||
const level = Number.parseInt(fields.openresty_gzip_comp_level, 10)
|
||||
if (Number.isNaN(level) || level < 1 || level > 9) {
|
||||
throw new Error("gzip_comp_level 必须在 1 到 9 之间")
|
||||
}
|
||||
}
|
||||
|
||||
export function validateCacheFields(fields: PerformanceFields) {
|
||||
if (!fields.OpenRestyCacheEnabled) return
|
||||
if (!fields.OpenRestyCachePath.trim()) {
|
||||
if (!fields.openresty_cache_enabled) return
|
||||
if (!fields.openresty_cache_path.trim()) {
|
||||
throw new Error("启用缓存时必须填写 proxy_cache_path 目录")
|
||||
}
|
||||
if (
|
||||
!isCacheLevelsValue(fields.OpenRestyCacheLevels) ||
|
||||
!isDurationToken(fields.OpenRestyCacheInactive) ||
|
||||
!isSizeValue(fields.OpenRestyCacheMaxSize) ||
|
||||
!isDurationToken(fields.OpenRestyCacheLockTimeout)
|
||||
!isCacheLevelsValue(fields.openresty_cache_levels) ||
|
||||
!isDurationToken(fields.openresty_cache_inactive) ||
|
||||
!isSizeValue(fields.openresty_cache_max_size) ||
|
||||
!isDurationToken(fields.openresty_cache_lock_timeout)
|
||||
) {
|
||||
throw new Error("缓存 levels、inactive、max_size 或 lock_timeout 格式不合法")
|
||||
}
|
||||
if (!fields.OpenRestyCacheKeyTemplate.trim()) {
|
||||
if (!fields.openresty_cache_key_template.trim()) {
|
||||
throw new Error("启用缓存时必须填写缓存 Key 模板")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user