如何在 Ubuntu 22.04 上安装 OpenLiteSpeed 网络服务器

介绍

OpenLiteSpeed是一个优化的开源Web服务器,可用于管理和服务网站。OpenLiteSpeed具有有用的功能,使其成为许多安装的强大选择,包括Apache(https://www.apache.org/)兼容的重写规则,内置的基于Web的管理界面,以及针对服务器优化的自定义PHP处理。

在本教程中,您将在Ubuntu 22.04 服务器上安装和配置 OpenLiteSpeed。

前提条件

要完成本教程,您将需要一个 Ubuntu 22.04 服务器,具有sudo启用,非根用户和ufw防火墙启用,您可以通过遵循 Ubuntu 22.04 初始服务器设置来设置。

步骤 1 – 安装 OpenLiteSpeed

在使用OpenLiteSpeed之前,您需要安装它。OpenLiteSpeed提供了一个软件存储库,您可以使用Ubuntu的标准apt命令下载和安装服务器。

首先,更新包管理器的缓存:

1sudo apt update

然后安装任何正在进行的升级:

1sudo apt upgrade

如果被提示,输入您的密码,然后用Y确认安装。

要为您的 Ubuntu 系统启用此存储库,请下载并添加开发者的软件签名密钥:

1sudo wget -O - https://repo.litespeed.sh | sudo bash

wget 收集位于 OpenLitespeed 服务器上的 shell 脚本,该脚本将自动执行添加 Litespeed 存储库到 Ubuntu 的 apt 包管理器的必要步骤。

这个命令的输出将是:

 1[secondary_label Output]
 2Redirecting output to ‘wget-log’.
 3--2022-11-05 15:09:40--  http://rpms.litespeedtech.com/debian/lst_debian_repo.gpg
 4Resolving rpms.litespeedtech.com (rpms.litespeedtech.com)... 52.55.120.73
 5Connecting to rpms.litespeedtech.com (rpms.litespeedtech.com)|52.55.120.73|:80... connected.
 6HTTP request sent, awaiting response... 200 OK
 7Length: 1198 (1.2K) [application/octet-stream]
 8Saving to: ‘/etc/apt/trusted.gpg.d/lst_debian_repo.gpg’
 9
10/etc/apt/trusted.gpg.d/l 100%[==================================>]   1.17K  --.-KB/s in 0s      
11
122022-11-05 15:09:40 (169 MB/s) - ‘/etc/apt/trusted.gpg.d/lst_debian_repo.gpg’ saved [1198/1198]
13
14--2022-11-05 15:09:40--  http://rpms.litespeedtech.com/debian/lst_repo.gpg
15Resolving rpms.litespeedtech.com (rpms.litespeedtech.com)... 52.55.120.73
16Connecting to rpms.litespeedtech.com (rpms.litespeedtech.com)|52.55.120.73|:80... connected.
17HTTP request sent, awaiting response... 200 OK
18Length: 2336 (2.3K) [application/octet-stream]
19Saving to: ‘/etc/apt/trusted.gpg.d/lst_repo.gpg’
20
21/etc/apt/trusted.gpg.d/l 100%[==================================>]   2.28K  --.-KB/s in 0s      
22
232022-11-05 15:09:41 (125 MB/s) - ‘/etc/apt/trusted.gpg.d/lst_repo.gpg’ saved [2336/2336]
24
25LiteSpeed repository has been setup!

更新存储库列表,以确保 apt 包管理器扫描新添加的存储库:

1sudo apt update

要安装 OpenLitespeed 服务器和相应的 LiteSpeed PHP 解释器,请运行命令:

1sudo apt install openlitespeed lsphp81

如果被提示,输入您的密码,然后用Y确认安装。

此命令安装了 Openlitespeed 服务器包和 LSPHP 8.1. LiteSpeed PHP (LSPHP)是与 LiteSpeed Server Application Programming Interface (LSAPI)集成的 PHP 解释器。

现在OpenLiteSpeed服务器已安装,您将通过更新默认管理员帐户来保护它。

步骤二:设置管理密码

在测试服务器之前,您将为 OpenLiteSpeed 设置一个新的管理密码. 您可以通过运行由 OpenLiteSpeed 提供的脚本来完成此操作:

1sudo /usr/local/lsws/admin/misc/admpass.sh

您将被要求为管理员用户提供一个用户名。 如果您按下ENTER而不选择新用户名,则将使用默认用户名admin。您可以使用您喜欢的任何管理员用户名。然后您将被要求为帐户创建并确认新的密码。 输入您喜欢的管理员密码,然后再次按下ENTER。 脚本将确认成功更新:

1[secondary_label Output]
2Administrator's username/password is updated successfully!

您现在已经保护了管理员帐户,接下来,您将测试服务器,以确保它正常运行。

步骤 3 – 连接到服务器

在此步骤中,您将连接到您的服务器。

安装后,OpenLiteSpeed 应该自动启动,您可以验证它是否用systemctl status命令启动:

1sudo systemctl status lsws

此命令将打印以下输出:

 1[secondary_label Output]
 2 lshttpd.service - OpenLiteSpeed HTTP Server
 3     Loaded: loaded (/etc/systemd/system/lshttpd.service; enabled; vendor preset: enabled)
 4     Active: active (running) since Sat 2022-11-05 15:11:24 UTC; 44s ago
 5    Process: 5458 ExecStart=/usr/local/lsws/bin/lswsctrl start (code=exited, status=0/SUCCESS)
 6   Main PID: 5486 (litespeed)
 7     CGroup: /system.slice/lshttpd.service
 8             ├─5486 "openlitespeed (lshttpd - main)"
 9             ├─5495 "openlitespeed (lscgid)"
10             ├─5524 "openlitespeed (lshttpd - #01)"
11             └─5525 lsphp "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ">
12
13Nov 05 15:11:21 ubuntu-s-1vcpu-1gb-blr1-01 systemd[1]: Starting OpenLiteSpeed HTTP Server...
14Nov 05 15:11:22 ubuntu-s-1vcpu-1gb-blr1-01 lswsctrl[5458]: [OK] litespeed: pid=5486.
15Nov 05 15:11:24 ubuntu-s-1vcpu-1gb-blr1-01 systemd[1]: Started OpenLiteSpeed HTTP Server.

活跃(运行)消息表示 OpenLiteSpeed 正在运行。

如果您的服务器不运行,您可以使用systemctl启动服务器:

1sudo systemctl start lsws

systemctl start命令将打印以下输出:

1[secondary_label Output]
2[OK] litespeed: pid=5137.

服务器现在应该运行. 按CTRL+C来退出服务输出。

在浏览器中访问之前,您需要在防火墙上打开一些端口,您可以通过ufw命令实现:

1sudo ufw allow 8088,7080,443,80/tcp

第一个端口,即8088,是 OpenLiteSpeed 示例网站的默认端口. 允许其使用ufw后,它现在应该向公众开放。 在您的 Web 浏览器中,导航到您的服务器的 IP 地址或域名,然后是:8088来指定端口:

1http://server_domain_or_IP:8088

您的浏览器将加载默认的 OpenLiteSpeed 网页,该网页将匹配下面的图像:

Screencapture of the default OpenLiteSpeed demo page

页面底部的链接展示了服务器的各种功能. 如果您点击它们,您可能会注意到这些功能已经安装和正确配置,包括可用的示例 CGI 脚本,正在运行的自定义 PHP 实例,以及已配置的自定义错误页面和身份验证端口。

当您对默认网站满意时,您可以转到管理界面. 在您的 Web 浏览器中,使用 HTTPS 导航到您的服务器的域名或 IP 地址,然后按 :7080 来指定端口:

1https://server_domain_or_IP:7080

您可能会看到一页向您发出警告,即服务器上的SSL证书无法验证,因为这是一个 自签证书,因此预期会收到此消息。 点击可用的选项即可进入网站。 在Chrome中,您必须点击 Advanced ,然后点击 继续到...

您将被要求输入您在上一步中使用admpass.sh脚本选择的管理用户名和密码:

screencapture of the OpenLiteSpeed admin login page

一旦验证,您将被介绍为 OpenLiteSpeed 管理界面:

screenshot of the OpenLiteSpeed admin dashboard

您对 Web 服务器的大部分配置将通过此仪表板进行。

在此步骤中,您通过新打开的端口连接到服务器,然后更新默认页面使用的端口。

步骤 4 – 更改默认页面的端口

要展示如何通过 Web 界面配置选项,您将将默认网站使用的端口从8088更改为常规的 HTTP 端口(80).

首先,在侧导航栏上的选项列表中点击 Listeners . 将加载所有可用的倾听者列表。

从此列表中,点击放大玻璃,这是 View 按钮,用于 Default 倾听器:

screencapture of OpenLiteSpeed's listeners summary page

此操作将加载有关 Default 倾听器的更多细节的页面,点击编辑按钮(笔和纸符号)在 Address Settings 表的右上角,以更改其值:

screencapture of OpenLiteSpeed's listener detail page

此按钮将打开一个新的屏幕. 更改端口 8088 到端口 80,然后点击 ** 保存** 按钮(磁盘符号):

screencapture of OpenLiteSpeed's listener update interface

保存修改后,您将需要重新启动服务器. 点击箭头图标,以获取将重启 OpenLiteSpeed 的 Graceful Restart 操作:

screencapture displaying the arrow for the graceful restart button

如果您被要求重新启动 LiteSpeed,请按 Go 按钮。

默认网页现在应该在您的浏览器中可访问的端口80而不是端口8088。访问您的服务器的域名或IP地址而不提供端口号将现在显示网站。

您现在可以添加任何HTML,CSS,JS或其他文件,您希望在您的网站上添加到位于/usr/local/lsws/Example/html的目录中。

结论

在这一点上,你有OpenLiteSpeed和PHP安装并运行在Ubuntu 22.04服务器上。OpenLiteSpeed提供出色的性能,基于Web的配置界面和预配置的脚本处理选项。

OpenLiteSpeed 是一个功能齐全的 Web 服务器,主要是通过管理 Web 界面来管理。

  • 联合国 与OpenLiteSpeed相关的一切信息将在`usr/local/lsws'目录下找到。
  • 默认虚拟主机的文档根( 您的文件将从何处服务) 位于 `/usr/local/lsws/example/html' 。 这个虚拟主机的配置和日志可见于"/usr/local/lsws/example"目录下.
  • 您可以使用管理员界面为不同的站点创建新的虚拟主机. 然而,所有设置您的配置时引用的目录必须提前创建 。 OpenLiteSpeed 无法创建目录 。
  • 您可以为相同一般格式的虚拟主机设置虚拟主机模板.
  • 您可以考虑使用默认虚拟主机的目录结构和配置作为新配置的起点.
  • 管理员界面有一个内置的工具提示帮助系统,几乎适用于所有字段. 导航菜单中还有一个 ** 帮助 ** 菜单选项链接到服务器文档. 如果您需要更多帮助, 请在配置过程中咨询这些信息来源 。
  • 要用 HTTPS 保护您的 OpenLiteSpeed 安装, 请参看 [SSL setup] (https://openlitespeed.org/kb/ssl-setup/) 上的正式文件 。 (英语)

您还可以继续使用使用 OpenLiteSpeed 的堆栈设置进行构建,如下 如何在 Ubuntu 22.04 上安装 Linux, OpenLiteSpeed, MariaDB, PHP (LOMP 堆栈)

Published At
Categories with 技术
comments powered by Disqus