OpenResty 是一个基于 Nginx 与 Lua 的高性能 Web 平台,其内部集成了大量精良的 Lua 库、第三方模块以及大多数的依赖项。用于方便地搭建能够处理超高并发、扩展性极高的动态 Web 应用、Web 服务和动态网关。
OpenResty 官方 APT 包仓库提供了 deb 包 (适用于 Ubuntu 和 Debian),可以很方便的安装,一起来看下具体的安装步骤吧。
|
1 2 3 |
$ apt update # 这一步选做 $ apt upgrade |
可以在 Debian 系统中添加 openresty 仓库,这样就可以方便的安装或更新我们的软件包(通过 apt update 命令)。
运行下面的命令就可以添加我们的仓库(每个系统只需要运行一次):
步骤一:安装导入 GPG 公钥时所需的几个依赖包(整个安装过程完成后可以随时删除它们):
|
1 |
sudo apt -y install --no-install-recommends wget gnupg ca-certificates |
步骤二:导入我们的 GPG 密钥:
|
1 |
wget -O - https://openresty.org/package/pubkey.gpg | sudo apt-key add - |
步骤三:添加我们官方 APT 仓库。
对于 x86_64 或 amd64 系统,可以使用下面的命令:
|
1 2 3 4 5 6 |
codename=`grep -Po 'VERSION="[0-9]+ \(\K[^)]+' /etc/os-release`
echo $codename
echo "deb http://openresty.org/package/debian $codename openresty" \ | sudo tee /etc/apt/sources.list.d/openresty.list |
这历史查找当前 debian 系统的版本(即 $codename 变量),更加系统版本再配置。
|
1 2 3 4 5 |
root@VM-4-14-debian:/opt# codename=`grep -Po 'VERSION="[0-9]+ \(\K[^)]+' /etc/os-release` root@VM-4-14-debian:/opt# echo $codename root@VM-4-14-debian:/opt# bullseye root@VM-4-14-debian:/opt# echo "deb http://openresty.org/package/debian bullseye openresty" | sudo tee /etc/apt/sources.list.d/openresty.list deb http://openresty.org/package/debian bullseye openresty |
而对于 arm64 或 aarch64 系统,则可以使用下面的命令:
|
1 2 3 4 |
codename=`grep -Po 'VERSION="[0-9]+ \(\K[^)]+' /etc/os-release`
echo "deb http://openresty.org/package/arm64/debian $codename openresty" \ | sudo tee /etc/apt/sources.list.d/openresty.list |
更新APT索引并安装
步骤四:更新 APT 索引:
|
1 |
sudo apt update |
然后就可以像下面这样安装软件包,比如 openresty:
|
1 |
sudo apt -y install openresty |
这个包同时也推荐安装 openresty-opm 和 openresty-restydoc 包,所以后面两个包会缺省安装上。
如果你不想自动关联安装,可以用下面方法关闭自动关联安装:
|
1 |
sudo apt -y install --no-install-recommends openresty |
openresty-opm 是 OpenResty 的包管理工具(OpenResty package manager)。
安装目录: /usr/local/openresty
|
1 2 3 4 5 |
$ nginx -v nginx version: openresty/1.21.4.1
$ /usr/local/openresty/nginx/sbin/nginx -v nginx version: openresty/1.21.4.1 |
使用 systemctl 可以管理openresty服务:
|
1 2 3 4 5 |
systemctl enable openresty systemctl status openresty systemctl start openresty systemctl stop openresty systemctl restart openresty |
验证效果,通过 curl 命令请求 localhost :
|
1 2 3 4 5 6 7 8 9 10 |
root@VM-4-14-debian:~# curl -I localhost HTTP/1.1 200 OK Server: openresty/1.21.4.1 Date: Sun, 09 Oct 2022 14:04:10 GMT Content-Type: text/html Content-Length: 1097 Last-Modified: Tue, 17 May 2022 03:51:45 GMT Connection: keep-alive ETag: "62831bd1-449" Accept-Ranges: bytes |
也可以打开浏览器 ,访问服务器ip,查看页面验证。
https://wang123.net/a/linux-debian-install-openresty
https://openresty.org/cn/linux-packages.html