LiteSpeed Web Server 使用指南

LiteSpeed Web Server Usage Guide

概述 (Overview)

LiteSpeed Web Server是一款高性能的商业Web服务器,以其卓越的性能、Apache兼容性和先进的缓存技术而著称。LiteSpeed提供了比Apache更高的性能和比Nginx更好的Apache兼容性,支持.htaccess和Apache Rewrite规则,是Apache的完美替代升级方案。

LiteSpeed Web Server is a high-performance commercial web server known for its excellent performance, Apache compatibility, and advanced caching technology. LiteSpeed offers better performance than Apache and better Apache compatibility than Nginx, supporting .htaccess and Apache Rewrite rules, making it a perfect drop-in replacement for Apache.

核心特性 (Core Features)

⚡ 极致性能 (Ultimate Performance)

  • 事件驱动架构: 比Apache快数倍
  • 更低资源消耗: 内存和CPU使用优化
  • 高并发处理: 数千并发连接
  • HTTP/3支持: QUIC协议原生支持

🔄 Apache兼容性 (Apache Compatibility)

  • 直接读取Apache配置文件
  • 完整支持.htaccess
  • mod_rewrite规则兼容
  • 零配置迁移
  • 控制面板兼容(cPanel/Plesk)

🚀 LSCache技术 (LSCache Technology)

  • 内置缓存引擎
  • WordPress/Magento/Drupal专用插件
  • 边缘侧包含(ESI)支持
  • 对象缓存
  • 数据库查询缓存

🛡️ 安全特性 (Security Features)

  • 抗DDoS攻击
  • ModSecurity兼容
  • 请求过滤
  • IP级访问控制
  • 自动SSL/TLS优化

产品版本 (Product Editions)

LiteSpeed Web Server (商业版)

  • Standard: $0/月(1 worker)- 免费版
  • Starter: $15/月(2 workers)
  • Professional: $59/月(无限workers)
  • Enterprise: $95/月(全部功能+集群)

OpenLiteSpeed (开源版)

  • 完全免费
  • 核心功能完整
  • 缺少部分企业功能
  • 社区支持
  • WebAdmin控制台

LiteSpeed Cache for CDN

  • QUIC.cloud CDN服务
  • 全球CDN节点
  • 免费和付费计划
  • 与LSCache无缝集成

性能对比 (Performance Comparison)

基准测试结果

静态文件服务(相对于Apache):
LiteSpeed: 9倍更快

PHP应用(WordPress):
LiteSpeed: 3-5倍更快

SSL/TLS连接:
LiteSpeed: 3倍更快(HTTP/3)

并发连接数:
Apache: ~500
Nginx: ~10000
LiteSpeed: ~10000+

资源使用对比

服务器 内存使用 CPU使用 性能得分
Apache ⭐⭐⭐
Nginx ⭐⭐⭐⭐⭐
LiteSpeed ⭐⭐⭐⭐⭐

OpenLiteSpeed 安装 (OpenLiteSpeed Installation)

Ubuntu/Debian安装

# 添加LiteSpeed仓库
wget -O - http://rpms.litespeedtech.com/debian/enable_lst_deblan_repo.sh | sudo bash

# 安装OpenLiteSpeed
sudo apt update
sudo apt install openlitespeed

# 安装PHP(lsphp)
sudo apt install lsphp74

# 设置管理员密码
sudo /usr/local/lsws/admin/misc/admpass.sh

# 启动服务
sudo systemctl start lsws
sudo systemctl enable lsws

# 访问WebAdmin: https://your-server-ip:7080
# 默认演示站点: http://your-server-ip:8088

CentOS/RHEL安装

# 添加仓库
sudo rpm -Uvh http://rpms.litespeedtech.com/centos/litespeed-repo-1.1-1.el7.noarch.rpm

# 安装
sudo yum install openlitespeed lsphp74

# 设置管理密码
sudo /usr/local/lsws/admin/misc/admpass.sh

# 启动
sudo systemctl start lsws

Docker部署

# 拉取OpenLiteSpeed镜像
docker pull litespeedtech/openlitespeed:latest

# 运行容器
docker run -d \
  --name openlitespeed \
  -p 7080:7080 \
  -p 80:80 \
  -p 443:443 \
  -v /path/to/sites:/var/www/vhosts \
  litespeedtech/openlitespeed:latest

商业版LiteSpeed安装 (Commercial LiteSpeed Installation)

# 下载安装脚本
wget https://www.litespeedtech.com/packages/lsws_trial.sh

# 运行安装(需要试用或正式license)
sudo bash lsws_trial.sh

# 配置向导会引导完成安装

# 或者直接下载包安装
wget https://www.litespeedtech.com/packages/6.0/lsws-6.0.7-ent-x86_64-linux.tar.gz
tar -xzf lsws-6.0.7-ent-x86_64-linux.tar.gz
cd lsws-6.0.7
sudo ./install.sh

配置管理 (Configuration Management)

虚拟主机配置

通过WebAdmin界面:

1. 登录 WebAdmin (https://server-ip:7080)
2. Virtual Hosts → Add
3. 配置虚拟主机参数:
   - Name: example.com
   - Root: $SERVER_ROOT/example.com/html
   - Domain: example.com, www.example.com
   - Enable Scripts: Yes

配置文件位置

LiteSpeed配置文件结构:
/usr/local/lsws/
├── conf/
│   ├── httpd_config.xml    (主配置)
│   ├── vhosts/             (虚拟主机配置)
│   └── templates/          (配置模板)
├── admin/                  (管理界面)
├── logs/                   (日志文件)
├── bin/                    (二进制文件)
└── fcgi-bin/              (FastCGI应用)

基本配置示例

<!-- httpd_config.xml 片段 -->
<httpServerConfig>
  <serverName>LiteSpeed</serverName>
  <user>nobody</user>
  <group>nogroup</group>
  <adminEmails>admin@example.com</adminEmails>

  <logging>
    <log>
      <fileName>$SERVER_ROOT/logs/error.log</fileName>
      <logLevel>INFO</logLevel>
      <rollingSize>10M</rollingSize>
    </log>
  </logging>

  <tuning>
    <maxConnections>10000</maxConnections>
    <maxSSLConnections>5000</maxSSLConnections>
    <connTimeout>300</connTimeout>
    <maxKeepAliveReq>1000</maxKeepAliveReq>
    <smartKeepAlive>1</smartKeepAlive>
  </tuning>
</httpServerConfig>

Apache迁移 (Apache Migration)

零配置迁移步骤

# 1. 备份Apache配置
sudo cp /etc/httpd/conf/httpd.conf /backup/

# 2. 停止Apache
sudo systemctl stop httpd
sudo systemctl disable httpd

# 3. 安装LiteSpeed
sudo bash lsws_trial.sh

# 4. 导入Apache配置
sudo /usr/local/lsws/admin/misc/ap2ls.sh /etc/httpd/conf/httpd.conf

# 5. 启动LiteSpeed
sudo systemctl start lsws

# 6. 测试
curl http://localhost

.htaccess支持

LiteSpeed完全支持Apache的.htaccess文件:

# .htaccess 示例
# URL重写
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

# 缓存控制
<FilesMatch "\.(jpg|jpeg|png|gif|css|js)$">
    Header set Cache-Control "max-age=2592000, public"
</FilesMatch>

# 压缩
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/xml
</IfModule>

# PHP设置
php_value upload_max_filesize 100M
php_value post_max_size 100M

LSCache配置 (LSCache Configuration)

启用LSCache

# WebAdmin界面启用
Server Configuration → Modules → Add
Module: cache

WordPress LSCache插件

# 在WordPress后台安装
1. 插件 → 安装插件
2. 搜索 "LiteSpeed Cache"
3. 安装并激活

# 主要功能:
- 页面缓存
- 对象缓存(Redis/Memcached)
- 数据库优化
- 图片优化
- CSS/JS压缩和合并
- CDN集成
- 延迟加载

LSCache规则示例

# .htaccess中的LSCache规则
<IfModule LiteSpeed>
    # 启用缓存
    CacheLookup on

    # 缓存时间
    CacheDefaultExpire 3600

    # 私有缓存(用户特定)
    CachePrivate on

    # 排除特定URL
    RewriteRule ^admin/ - [E=Cache-Control:no-cache]
    RewriteRule ^wp-admin/ - [E=Cache-Control:no-cache]

    # 移动端单独缓存
    CacheVary Mobile
</IfModule>

ESI (Edge Side Includes)

<!-- 页面中使用ESI -->
<esi:include src="/api/user-info" />

<!-- 缓存策略 -->
<!-- 页面缓存1小时,user-info组件缓存5分钟 -->

HTTP/3和QUIC配置 (HTTP/3 and QUIC Configuration)

启用HTTP/3

<!-- httpd_config.xml -->
<listener>
  <name>Default HTTPS</name>
  <address>*:443</address>
  <secure>1</secure>
  <enableQuic>1</enableQuic>

  <certFile>$SERVER_ROOT/conf/ssl/cert.pem</certFile>
  <keyFile>$SERVER_ROOT/conf/ssl/key.pem</keyFile>
</listener>

验证HTTP/3

# 使用curl验证
curl --http3 https://example.com -I

# 浏览器开发者工具
# Network → Protocol列查看h3

性能调优 (Performance Tuning)

连接优化

<tuning>
  <!-- 最大连接数 -->
  <maxConnections>10000</maxConnections>
  <maxSSLConnections>5000</maxSSLConnections>

  <!-- 连接超时 -->
  <connTimeout>300</connTimeout>
  <keepAliveTimeout>5</keepAliveTimeout>

  <!-- Keep-Alive优化 -->
  <maxKeepAliveReq>1000</maxKeepAliveReq>
  <smartKeepAlive>1</smartKeepAlive>

  <!-- 带宽限制 -->
  <inBandwidth>0</inBandwidth>
  <outBandwidth>0</outBandwidth>
</tuning>

PHP性能优化

# 使用LiteSpeed SAPI (LSPHP)
# 比FastCGI更快

# 配置PHP-FPM(如果使用)
External App → Add → Type: LSAPI
Name: lsphp74
Address: uds://tmp/lshttpd/lsphp.sock
Max Connections: 35
Environment: PHP_LSAPI_CHILDREN=35
Initial Request Timeout: 60
Retry Timeout: 0

静态资源优化

<expires>
  <enableExpires>1</enableExpires>
  <expiresDefault>A86400</expiresDefault>
  <expiresByType>
    image/*=A2592000, text/css=A604800, application/javascript=A604800
  </expiresByType>
</expires>

安全配置 (Security Configuration)

防火墙规则

# UFW防火墙配置
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw allow 443/udp  # HTTP/3
sudo ufw allow 7080/tcp # WebAdmin (限制IP)

抗DDoS配置

<security>
  <!-- 连接限制 -->
  <perClientConnLimit>50</perClientConnLimit>
  <staticReqPerSec>100</staticReqPerSec>
  <dynReqPerSec>10</dynReqPerSec>

  <!-- 带宽限制 -->
  <inBandwidth>10240</inBandwidth>
  <outBandwidth>20480</outBandwidth>

  <!-- 黑名单 -->
  <accessControl>
    <allow>ALL</allow>
    <deny>192.168.1.100, 10.0.0.0/8</deny>
  </accessControl>
</security>

ModSecurity集成

# 安装ModSecurity
sudo apt install libmodsecurity3
sudo apt install litespeed-modsecurity

# 配置ModSecurity规则
# /usr/local/lsws/conf/modsecurity.conf

监控与日志 (Monitoring and Logging)

实时统计

访问WebAdmin → Actions → Real-Time Stats

  • 实时请求数
  • 连接数
  • 带宽使用
  • 响应时间

日志配置

<logging>
  <log>
    <useServer>1</useServer>
    <fileName>$SERVER_ROOT/logs/$VH_NAME/access.log</fileName>
    <logFormat>%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-agent}i"</logFormat>
    <rollingSize>100M</rollingSize>
    <keepDays>30</keepDays>
  </log>
</logging>

日志分析

# 使用GoAccess分析日志
sudo apt install goaccess
goaccess /usr/local/lsws/logs/access.log -o /var/www/html/report.html --log-format=COMBINED

控制面板集成 (Control Panel Integration)

cPanel/WHM

  • LiteSpeed官方cPanel插件
  • 一键切换Apache到LiteSpeed
  • 保留cPanel所有功能

DirectAdmin

  • 原生LiteSpeed支持
  • CustomBuild脚本集成

Plesk

  • LiteSpeed扩展可用
  • 图形化配置

常用命令 (Common Commands)

# 启动/停止/重启
sudo systemctl start lsws
sudo systemctl stop lsws
sudo systemctl restart lsws

# 平滑重启(零停机)
sudo /usr/local/lsws/bin/lswsctrl restart

# 检查配置
sudo /usr/local/lsws/bin/lswsctrl configtest

# 查看版本
sudo /usr/local/lsws/bin/lshttpd -v

# 清除缓存
sudo rm -rf /usr/local/lsws/cachedata/*

# 查看实时日志
sudo tail -f /usr/local/lsws/logs/error.log

与其他服务器对比 (Comparison)

特性 LiteSpeed Nginx Apache
性能 ⭐⭐⭐⭐⭐ ⭐⭐⭐⭐⭐ ⭐⭐⭐
Apache兼容 ✅ 完全 ❌ 不兼容
.htaccess
内置缓存 ✅ LSCache
HTTP/3 ✅ 原生 ✅ 实验性 ⚠️ 有限
开源 ⚠️ 部分
价格 免费-付费 免费 免费
学习曲线 平缓 中等 中等
控制面板 ✅ 原生 ⚠️ 需配置 ✅ 原生

使用场景 (Use Cases)

✅ 理想场景

  • Apache升级替换
  • WordPress/Magento/Joomla站点
  • 需要高性能的PHP应用
  • 使用cPanel/Plesk等控制面板
  • 需要.htaccess支持
  • 共享主机环境
  • 需要强大缓存功能

⚠️ 考虑其他方案

  • 纯静态站点(Nginx即可)
  • 非PHP应用(考虑Nginx)
  • 开源方案强制要求(用OpenLiteSpeed)
  • 预算极其受限(用Nginx)

学习资源 (Learning Resources)

总结 (Summary)

LiteSpeed Web Server是Apache的理想升级替代方案,特别适合:

  1. Apache用户: 零配置迁移,完全兼容
  2. WordPress站长: LSCache插件提供卓越性能
  3. 共享主机商: 高性能、低资源消耗
  4. 企业用户: 商业支持和高级功能

主要优势

  • ✅ 比Apache快3-9倍
  • ✅ 完全兼容Apache配置
  • ✅ 强大的内置缓存(LSCache)
  • ✅ HTTP/3原生支持
  • ✅ 商业和开源版本可选
  • ✅ 控制面板友好

无论是个人博客还是大型电商网站,LiteSpeed都能提供卓越的性能和稳定性。


最后更新: 2025年11月

Last Updated: November 2025

powered by Gitbook© 2025 编外计划 | 最后修改: 2025-11-25 18:08:14

results matching ""

    No results matching ""