如何在Ubuntu 20.04上安装OpenLiteSpeed Web服务器
引言
OpenLiteSpeed是一个经过优化的开源Web服务器,可用于管理和提供网站。 OpenLiteSpeed具有一些有用的功能,使其成为许多安装的可靠选择,包括与Apache兼容的重写规则,内置的基于Web的管理界面以及针对服务器进行优化的自定义PHP处理。
在本教程中,您将在Ubuntu 20.04服务器上安装和配置OpenLiteSpeed。
先决条件
要完成本教程,您需要一个已启用sudo权限、非root用户的Ubuntu 20.04服务器,并启用了ufw防火墙,您可以按照《使用Ubuntu 20.04进行初始服务器设置》进行设置。
第一步-安装OpenLiteSpeed
在使用OpenLiteSpeed之前,您需要安装它。OpenLiteSpeed提供了一个软件仓库,您可以使用Ubuntu的标准apt命令来下载和安装服务器。
先更新软件包管理器缓存。
- sudo apt update
然后安装任何待处理的升级。
- sudo apt upgrade
如果提示,输入您的密码,然后用Y确认安装。 tíshì, de , Y .)
为了让您的Ubuntu系统能够使用这个软件库,请下载并添加开发者的软件签名密钥。
- sudo wget -O – https://rpms.litespeedtech.com/debian/enable_lst_debian_repo.sh | sudo bash
wget从OpenLitespeed服务器上获取一个shell脚本,该脚本将自动执行必要的步骤,将Litespeed存储库添加到Ubuntu的apt软件包管理器中。 shell脚本的内容通过|管道传递给一个新的bash shell。
这个命令的输出将会是:
–2022-10-01 13:12:00– https://rpms.litespeedtech.com/debian/enable_lst_debian_repo.sh Resolving rpms.litespeedtech.com (rpms.litespeedtech.com)… 52.55.120.73 Connecting to rpms.litespeedtech.com (rpms.litespeedtech.com)|52.55.120.73|:443… connected. HTTP request sent, awaiting response… 200 OK Length: 3457 (3.4K) [application/x-sh] Saving to: ‘STDOUT’ – 0%[ ] 0 –.-KB/s detecting OS type : detected OS: ubuntu – 20.04 now enable the LiteSpeed Debian Repo – 100%[==================================>] 3.38K –.-KB/s in 0s 2022-10-01 13:12:01 (136 MB/s) – written to stdout [3457/3457] register LiteSpeed GPG key –2022-10-01 13:12:01– http://rpms.litespeedtech.com/debian/lst_debian_repo.gpg Resolving rpms.litespeedtech.com (rpms.litespeedtech.com)… 52.55.120.73 Connecting to rpms.litespeedtech.com (rpms.litespeedtech.com)|52.55.120.73|:80… connected. HTTP request sent, awaiting response… 200 OK Length: 1198 (1.2K) [application/octet-stream] Saving to: ‘/etc/apt/trusted.gpg.d/lst_debian_repo.gpg’ /etc/apt/trusted.gpg.d/l 100%[==================================>] 1.17K –.-KB/s in 0s 2022-10-01 13:12:02 (101 MB/s) – ‘/etc/apt/trusted.gpg.d/lst_debian_repo.gpg’ saved [1198/1198] –2022-10-01 13:12:02– http://rpms.litespeedtech.com/debian/lst_repo.gpg Resolving rpms.litespeedtech.com (rpms.litespeedtech.com)… 52.55.120.73 Connecting to rpms.litespeedtech.com (rpms.litespeedtech.com)|52.55.120.73|:80… connected. HTTP request sent, awaiting response… 200 OK Length: 2336 (2.3K) [application/octet-stream] Saving to: ‘/etc/apt/trusted.gpg.d/lst_repo.gpg’ /etc/apt/trusted.gpg.d/l 100%[==================================>] 2.28K –.-KB/s in 0s 2022-10-01 13:12:02 (312 MB/s) – ‘/etc/apt/trusted.gpg.d/lst_repo.gpg’ saved [2336/2336] update the repo Hit:1 http://mirrors.digitalocean.com/ubuntu focal InRelease Hit:2 http://mirrors.digitalocean.com/ubuntu focal-updates InRelease Hit:3 https://repos-droplet.digitalocean.com/apt/droplet-agent main InRelease Hit:4 http://mirrors.digitalocean.com/ubuntu focal-backports InRelease Hit:5 http://security.ubuntu.com/ubuntu focal-security InRelease Ign:6 http://rpms.litespeedtech.com/debian focal InRelease Hit:7 https://repos.insights.digitalocean.com/apt/do-agent main InRelease Get:8 http://rpms.litespeedtech.com/debian focal Release [1652 B] Get:9 http://rpms.litespeedtech.com/debian focal Release.gpg [836 B] Get:10 http://rpms.litespeedtech.com/debian focal/main amd64 Packages [19.0 kB] Fetched 21.5 kB in 1s (14.8 kB/s) Reading package lists… Done All done, congratulations and enjoy !
要安装OpenLitespeed服务器和对应的LS-PHP解释器,请运行以下命令:
- sudo apt install openlitespeed lsphp81
如果提示,请输入您的密码,然后用Y确认安装。
这个命令安装Openlitespeed服务器包和LSPHP 8.1。LiteSpeed PHP(LSPHP)是一个与LiteSpeed服务器应用程序编程接口(LSAPI)集成的PHP解释器。
现在安装了OpenLiteSpeed服务器,您将通过更新默认管理员帐户来确保其安全。
第二步 – 设置管理密码
在测试服务器之前,您需要为OpenLiteSpeed设置一个新的管理员密码。您可以通过运行OpenLiteSpeed提供的脚本来完成这个操作。
- sudo /usr/local/lsws/admin/misc/admpass.sh
您将被要求为管理员用户提供一个用户名。如果您按下回车键而没有选择一个新的用户名,将使用默认的admin。您可以使用您喜欢的任何管理员用户名。然后您将收到创建并确认账户密码的提示。输入您喜欢的管理员密码,然后再次按下回车键。脚本将确认更新成功。
Administrator’s username/password is updated successfully!
现在你已经成功地获得了管理员账户。接下来,你将测试服务器以确保其正常运行。
第三步 – 连接服务器
在这个步骤中,您将连接到您的服务器。
在OpenLiteSpeed安装完成后,它应该自动启动。你可以使用systemctl status命令来验证它是否已启动。
- sudo systemctl status lsws
这个命令将打印以下输出。
● lshttpd.service – OpenLiteSpeed HTTP Server Loaded: loaded (/etc/systemd/system/lshttpd.service; enabled; vendor preset: enabled) Active: active (running) since Sat 2022-10-01 13:22:01 UTC; 5min ago Process: 5805 ExecStart=/usr/local/lsws/bin/lswsctrl start (code=exited, status=0/SUCCESS) Main PID: 5843 (litespeed) CGroup: /system.slice/lshttpd.service ├─5843 openlitespeed (lshttpd – main) ├─5852 openlitespeed (lscgid) └─5881 openlitespeed (lshttpd – #01) Oct 01 13:21:58 ubuntu-s-1vcpu-1gb-blr1-01 systemd[1]: Starting OpenLiteSpeed HTTP Server… Oct 01 13:21:59 ubuntu-s-1vcpu-1gb-blr1-01 lswsctrl[5805]: [OK] litespeed: pid=5843. Oct 01 13:22:01 ubuntu-s-1vcpu-1gb-blr1-01 systemd[1]: Started OpenLiteSpeed HTTP Server.
运行中的消息表示OpenLiteSpeed正在运行。
如果您的服务器没有运行,您可以使用systemctl命令启动服务器。
- sudo systemctl start lsws
systemctl start命令会打印以下输出内容:
[OK] litespeed: pid=5137.
服务器现在应该已经在运行中。按下CTRL+C来退出服务输出。
在浏览器访问之前,你需要在防火墙上打开一些端口,你可以使用ufw命令来实现。
- sudo ufw allow 8088,7080,443,80/tcp
第一个端口8088是OpenLiteSpeed示例站点的默认端口。在使用ufw允许之后,它现在可以被公开访问。在您的网络浏览器中,输入您服务器的域名或IP地址,接着加上:8088来指定该端口。
http://server_domain_or_IP:8088
您的浏览器将加载默认的OpenLiteSpeed网页,该页面与下面的图片相匹配。

页面底部的链接展示了服务器的各种功能。如果你点击它们,你可能会注意到这些功能已经安装并正确配置,包括可用的示例CGI脚本、正在运行的定制PHP实例,以及已配置的自定义错误页面和身份验证门。
当你对默认站点感到满意时,你可以进入管理界面。在你的网络浏览器中,通过HTTPS访问你的服务器的域名或IP地址,然后跟上:7080来指定端口。
https://server_domain_or_IP:7080
你可能会看到一个页面警告你服务器的SSL证书无法验证。因为这是一个自签名的证书,所以这个消息是预期的。点击可用选项继续访问该网站。在Chrome中,你必须点击高级选项,然后继续访问。
您将会被要求输入您在前一步中使用admpass.sh脚本选择的管理用户名和密码。

在身份验证通过后,您将看到OpenLiteSpeed管理界面。

大多数网页服务器的配置将通过此控制面板进行。
在这个步骤中,你通过新开启的端口连接到服务器。接下来,你将更新默认页面使用的端口。
第四步 – 更改默认页面的端口
为了演示如何通过Web界面配置选项,您将把默认站点使用的端口从8088更改为传统的HTTP端口(80)。
从侧边导航栏的选项中选择“听众”。将加载出所有可用的听众列表。
从这个列表中,点击放大镜,也就是“查看”按钮,以查看默认监听器。

点击编辑按钮(顶部右上角有钢笔和纸片符号)打开该操作,将加载有关默认监听器更多细节的页面。在地址设置表中,修改其数值。

点击这个按钮将会打开一个新的画面。将端口8088改成端口80,然后点击保存按钮(软盘符号)。

保存修改后,您需要重新启动服务器。点击箭头图标以执行优雅重启操作,将重新启动OpenLiteSpeed。

如果出现要求重新启动LiteSpeed的提示,请按”Go”按钮。
现在应该可以在端口80上通过浏览器访问默认网页,而不是端口8088。访问服务器的域名或IP地址而不提供端口号将会显示该网站。
你现在可以将任何你希望在你的网站上展示的HTML、CSS、JS或其他文件添加到位于/usr/local/lsws/Example/html的目录中。
总结
OpenLiteSpeed是一个功能齐全的Web服务器,主要通过管理的Web界面进行管理。
您可以继续使用以下信息配置您的界面:
- Everything associated with OpenLiteSpeed will be found under the /usr/local/lsws directory.
- The document root (where your files will be served from) for the default virtual host is located at /usr/local/lsws/Example/html. The configuration and logs for this virtual host can be found under the /usr/local/lsws/Example directory.
- You can create new virtual hosts for different sites using the admin interface. However, all the directories that you reference when setting up your configuration must be created ahead of time. OpenLiteSpeed is not able to create the directories.
- You can set up virtual host templates for virtual hosts that share the same general format.
- You might consider using the default virtual host’s directory structure and configuration as a starting point for new configurations.
- The admin interface has a built-in tooltip help system for almost all fields. There is also a Help menu option in the navigation menu that links to the server documentation. Consult these sources of information during configuration if you need more help.
- To secure your OpenLiteSpeed installation with HTTPS, see the official documentation on SSL Setup.
在此时,您已经在Ubuntu 20.04服务器上安装并运行了OpenLiteSpeed和PHP。OpenLiteSpeed提供出色的性能、基于网络的配置界面以及预配置的脚本处理选项。