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

介绍

OpenLiteSpeed是一款优化的开源Web服务器,可用于管理和提供网站。OpenLiteSpeed拥有一些有用的功能,使其成为许多安装的首选,包括与Apache兼容的重写规则、内置的基于Web的管理界面以及为服务器优化的定制PHP处理。

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

先决条件

为了完成此教程,您需要一个启用了sudo权限且非root用户的Ubuntu 22.04服务器,以及启用了ufw防火墙。您可以按照使用Ubuntu 22.04进行初步服务器设置的步骤进行设置。

第一步 – 安装OpenLiteSpeed

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

首先更新软件包管理器的缓存。

  1. sudo apt update

然后安装所有未完成的升级。

  1. sudo apt upgrade

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

要在您的Ubuntu系统上启用这个软件仓库,请下载并添加开发者的软件签名密钥。

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

wget命令从OpenLitespeed服务器上获取一个shell脚本,该脚本将自动执行必要的步骤,将Litespeed软件仓库添加到Ubuntu的apt软件包管理器中。通过|管道将shell脚本的内容传递给新的bash shell。

这个命令的输出结果将会是:

Output
Redirecting output to ‘wget-log’. --2022-11-05 15:09:40-- 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-11-05 15:09:40 (169 MB/s) - ‘/etc/apt/trusted.gpg.d/lst_debian_repo.gpg’ saved [1198/1198] --2022-11-05 15:09:40-- 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-11-05 15:09:41 (125 MB/s) - ‘/etc/apt/trusted.gpg.d/lst_repo.gpg’ saved [2336/2336] LiteSpeed repository has been setup!

更新仓库列表,确保新添加的仓库被 apt 软件包管理器扫描。

  1. sudo apt update

运行以下命令以安装OpenLitespeed服务器和对应的LiteSpeed PHP解释器:

  1. sudo apt install openlitespeed lsphp81

如果收到提示,请输入您的密码,然后输入Y确认安装。

这个命令安装了Openlitespeed服务器包和LSPHP 8.1。LiteSpeed PHP (LSPHP) 是与LiteSpeed服务器应用程序编程接口(LSAPI)集成的PHP解释器。

现在OpenLiteSpeed服务器已安装完毕,您需要通过更新默认管理员账户来确保其安全。

第二步 – 设置管理员密码

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

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

您将被要求提供一个管理员用户的用户名。如果您按确认键而没有选择一个新的用户名,系统将使用默认的用户名admin。您可以使用任何您喜欢的管理员用户名。然后系统将提示您创建并确认一个新密码。输入您喜欢的管理员密码,然后再次按确认键。系统将确认更新成功。

Output
Administrator's username/password is updated successfully!

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

步骤3-连接服务器

在这一步中,您将连接到您的服务器。

安装完OpenLiteSpeed后,它应该会自动启动。您可以用systemctl status命令来验证它是否已经启动。

  1. sudo systemctl status lsws

这个命令将会打印以下结果。

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

活动中的消息表示OpenLiteSpeed正在运行。

如果你的服务器没有运行,你可以使用systemctl启动服务器。

  1. sudo systemctl start lsws

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

Output
[OK] litespeed: pid=5137.

服务器现在应该正在运行。按下Ctrl+C来退出服务输出。

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

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

第一个端口8088是OpenLiteSpeed示例站点的默认端口。在使用ufw允许后,现在可以对公众访问。在您的网页浏览器中,输入服务器的IP地址或域名,后面加上:8088来指定端口。

http://server_domain_or_IP:8088

您的浏览器将加载默认的OpenLiteSpeed网页,与以下图片匹配。

Screencapture of the default OpenLiteSpeed demo page

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

当您对默认站点感到满意时,您可以进入管理界面。在Web浏览器中,使用HTTPS导航到您的服务器的域名或IP地址,并在后面加上:7080以指定端口。

https://server_domain_or_IP:7080

很可能会看到一个提示页面,告诉你服务器的SSL证书无法验证。由于这是一个自签名证书,所以预期会出现这个消息。点击可用选项,继续访问该网站。在Chrome浏览器中,你必须点击“高级”然后点击“继续前往…”。

您将被提示输入在前一步中使用admpass.sh脚本选择的管理用户名和密码。

screencapture of the OpenLiteSpeed admin login page

一旦身份验证成功,您将会看到OpenLiteSpeed管理界面。

screenshot of the OpenLiteSpeed admin dashboard

大部分的网络服务器配置将通过这个控制面板进行。

在这一步骤中,您通过新开放的端口连接到服务器。接下来,您将更新默认页面使用的端口。

第四步 – 更改默认页面的端口

为了演示如何通过网页界面配置选项,您将把默认网站使用的端口从8088更改为常规的HTTP端口(80)。

从侧边导航栏的选项中开始点击”Listeners”。会加载所有可用的监听器列表。

从列表中,点击放大镜,即视图按钮,进入默认监听器。

screencapture of OpenLiteSpeed's listeners summary page

点击默认监听器(Address Settings表格右上角的铅笔和纸笔标志)编辑按钮,将加载含有有关默认监听器更多详细信息的页面,以修改其值。

screencapture of OpenLiteSpeed's listener detail page

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

screencapture of OpenLiteSpeed's listener update interface

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

screencapture displaying the arrow for the graceful restart button

如果提示您重新启动 LiteSpeed,请按下“Go”按钮。

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

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

结论

在这一步,你已经在一个Ubuntu 22.04服务器上安装并运行了OpenLiteSpeed和PHP。OpenLiteSpeed具有出色的性能、基于web的配置界面以及预配置的脚本处理选项。

OpenLiteSpeed是一个功能齐全的网页服务器,主要通过管理网页界面进行管理。您可以继续使用以下一些信息配置您的界面:

  • 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 22.04上安装Linux、OpenLiteSpeed、MariaDB和PHP(LOMP堆栈)》的指南,继续使用OpenLiteSpeed来进行构建。

发表回复 0

Your email address will not be published. Required fields are marked *