导读
在上一篇文章中,康诺使用 Proxmox 开启了虚拟机,也就是俗称的VPS。
本篇,将会在开启出来的VPS中安装配置 OpenLiteSpeed 并创建一个 WordPress 博客程序,完成网站搭建。
在搭建之前,随意介绍下今天的主角:OpenLiteSpeed
OpenLiteSpeed 是 LiteSpeed EnterPrise 的社区版本,相较 Nginx 很多扩展如 Brotli、nginx-cache-purge 等扩展,会因为更新的不及时导致对最新Stable版本的不支持,同时也没有企业级的保障。 而 OpenLiteSpeed 的组件有官方进行主要维护和更新,提供商用企业级的体验。
在性能上,LiteSpeed Tech 提供的 BenchMark 中,在 WordPress、Joomla、OpenCart、ModSecurity、小型静态文件、HTTP/2、HTTP/3 的测试上都比 Apache HTTPD 和 Nginx 有这更好的表现,这不仅仅是跑个 Hello World 而是进行一个完整的测试。
总的来说,OpenLiteSpeed 就是一款比 Nginx、Apache 等更优秀的商业开源版本的 Web 服务器软件,因为是商业公司开发,所以更新、修补及性能等有较好的保障,而且 OpenLiteSpeed 包含有一个插件 LSCache,这款插件是专门针对 WordPress 进行开发设计的,优化效果相较于其他缓存插件那是高了很多的。
基于此,本文将会着重讲解 OpenLiteSpeed 的安装以及 LSCache 的使用。
OpenLiteSpeed 安装
OpenLiteSpeed 有好几种方式,最简单的有官方的一键包,其他的还可以自己编译等等,这里就讲解一键包以及 FreeBSD 下编译两种方式吧。
官方一键包
直接输入命令进行安装配置:
wget --no-check-certificate https://github.com/litespeedtech/ols1clk/raw/master/ols1clk.sh
bash ols1clk.sh --adminpassword free.gd --email [email protected] --lsphp 81 --listenport 80 --ssllistenport 443执行后,将会自动为您安装 OpenLiteSpeed,并配置管理员密码为 free.gd,管理员邮箱为 [email protected],以及安装 lsphp81,监听 80 及 443 两个 Web 端口,由于康诺在服务器上单独开设了一台小鸡作为 MySQL 数据库服务器,所以这里没有安装 MySQL,需要安装的可以看看下方的完整命令列表:
--adminpassword [PASSWORD] To set the WebAdmin password for OpenLiteSpeed instead of using a random one.
--email [EMAIL] To set the administrator email.
--lsphp [VERSION] To set the LSPHP version, such as 80. We currently support versions '71 72 73 74 80 81'.
--mariadbver [VERSION] To set MariaDB version, such as 10.9. We currently support versions '10.2 10.3 ...10.9'.
--wordpress To install WordPress. You will still need to complete the WordPress setup by browser
--wordpressplus [SITEDOMAIN] To install, set up, and configure WordPress, also LSCache will be enabled
--wordpresspath [WP_PATH] To specify a location for the new WordPress installation or use for an existing WordPress.
--dbrootpassword [PASSWORD] To set the database root password instead of using a random one.
--dbname [DATABASENAME] To set the database name to be used by WordPress.
--dbuser [DBUSERNAME] To set the WordPress username in the database.
--dbpassword [PASSWORD] To set the WordPress table password in MySQL instead of using a random one.
--prefix [PREFIXNAME] To set the WordPress table prefix.
--listenport [PORT] To set the HTTP server listener port, default is 80.
--ssllistenport [PORT] To set the HTTPS server listener port, default is 443.
--wpuser [WP_USER] To set the WordPress admin user for WordPress dashboard login. Default value is wpuser.
--wppassword [PASSWORD] To set the WordPress admin user password for WordPress dashboard login.
--wplang [WP_LANGUAGE] To set the WordPress language. Default value is "en_US" for English.
--sitetitle [WP_TITLE] To set the WordPress site title. Default value is mySite.
--pure-mariadb To install OpenLiteSpeed and MariaDB.
--with-mysql To install OpenLiteSpeed/App with MySQL.
--proxy-r To set a proxy with rewrite type.
--proxy-c To set a proxy with config type.
--uninstall To uninstall OpenLiteSpeed and remove installation directory.
--purgeall To uninstall OpenLiteSpeed, remove installation directory, and purge all data in MySQL.
--quiet To use quiet mode, won't prompt to input anything.
--version To display the script version information.
--verbose To display more messages during the installation.
--update To update ols1clk from github.
--help To display help messages.
源码编译
这里使用 FreeBSD 作为解说,描述下在 FreeBSD 下如何进行 OpenLiteSpeed 的源码编译。
首先更新 ports:
portsnap fetch extract接着依次安装以下组件:
cd /usr/ports/devel/pcre; make install clean; rehash;
cd /usr/ports/devel/rcs; make install clean; rehash;
cd /usr/ports/dns/udns; make install clean; rehash;
cd /usr/ports/textproc/expat2; make install clean; rehash;
cd /usr/ports/security/openssl; make install clean; rehash;
cd /usr/ports/lang/perl5.26; make install clean; rehash;下载 OpenLiteSpeed 源码到本地,解压并安装:
fetch https://openlitespeed.org/packages/openlitespeed-1.7.16.src.tgz
tar zxf openlitespeed-1.7.16.src.tgz
cd openlitespeed-1.7.16
./configure --with-pcre=/usr/localOpenLiteSpeed 配置
OpenLiteSpeed 已经安装完成,接着,咱们输入 https://ip:7080 访问 OpenLiteSpeed 控制面板(没错,自带了控制面板),可却发现打不开,什么情况?
这是由于 OpenLiteSpeed 默认监听 IPv4,而不监听 IPv6 的原因,这就导致咱们直接使用 IPv6 无法访问,此时登录服务器,并修改 /usr/local/lsws/admin/conf/admin_config.conf 文件,将其中的 *:7080 修改为 [ANY]:7080,然后执行重启
/usr/local/lsws/bin/lswsctrl restart再次打开控制面板,并输入帐号名称 admin 及自己配置或程序随机生成的密码登录控制面板。
登录后,在控制面板右上角可以修改语言为中文。
点击左侧的 虚拟主机,并点击 "+" 添加一个虚拟主机并填写网站基本信息。
点击保存图标保存,会出现 file /usr/local/lsws/conf/vhosts/free.gd/vhconf.conf does not exist. CLICK TO CREATE 这样的一段提示,咱们点击 CLICK TO CREATE 创建配置文件后再次提交即可,接着按照提示一步一步的完成即可。
配置完成后发现依然无法打开网站,这是因为还没有将网站添加到监听的端口中。
点击左侧 监听器,可以看到后台已经默认配置了两个监听接口,一个是 HTTP 的 80 端口,一个是 HTTPS 的 443 端口。
接下来,依次点击 放大镜,并点击 "+" 将自己刚才创建的虚拟主机加入到接口中,记住两个端口都要添加!
此时,咱们网站也创建完成了,到 MySQL 服务器中创建一个数据库及专属用户,接着在网站服务器中执行命令:
mkdir -p /srv/www/free.gd
cd /srv/www/free.gd
fetch https://WordPress.org/latest.tar.gz
tar zxf latest.tar.gz
rm -f latest.tar.gz
mv WordPress public_html
chown -R nobody:nogroup /srv/www/free.d
chmod -R 755 /srv/www/free.gd
/usr/local/lsws/bin/lswsctrl restart访问域名开始安装 WordPress。
LSCache配置
在 WordPress 后台安装插件 LiteSpeed Cache 并激活,根据自己的需要进行自定义配置,这里最主要记得开启 对象缓存 与 即时点击,其余自行决定。
完成以上步骤后,已经基本OK,不过,为了更好的缓存效果,咱们回到 OpenLiteSpeed 控制面板,进入刚才添加的虚拟主机中,在 资源集 下依次添加几条静态规则。
第一条
URI: /wp-content/cache/js/
位置: $DOC_ROOT/wp-content/cache/js/
可访问: yes
启用过期: yes
按类型过期: application/x-javascript=A15552000,
text/javascript=A15552000, application/javascript=A15552000
头部操作:
unset Cache-control set Cache-control public, max-age=15552000 set
Access-Control-Allow-Origin: *
第二条
URI: /wp-content/cache/css/
位置: $DOC_ROOT/wp-content/cache/css/
可访问: yes
启用过期: yes
按类型过期: text/css=A15552000
头部操作:
unset Cache-control
set Cache-control public, max-age=15552000
set Access-Control-Allow-Origin: *
第三条
URI: exp:^.*(gif|ico|jpeg|jpg|png|webp|woff|woff2|fon|fot|ttf)位置:DOC_ROOT/$0
可访问: yes
启用过期: yes
按类型过期: text/css=A15552000, image/gif=A15552000, image/x-icon=A15552000, image/jpeg=A15552000, application/x-javascript=A15552000, text/javascript=A15552000, application/javascript=A15552000, image/png=A15552000, image/webp=A15552000, font/ttf=A15552000, font/woff=A15552000, font/woff2=A15552000, application/x-font-ttf=A15552000, application/x-font-woff=A15552000, application/font-woff=A15552000, application/font-woff2=A15552000
头部操作:
unset Cache-control
set Cache-control public, max-age=15552000
set Access-Control-Allow-Origin: *
完成后效果如图
完成后再次重启即可
/usr/local/lsws/bin/lswsctrl restart






