小知识:在Debian11上安装Openresty服务(Nginx+Lua)的详细教程

OpenResty 是一个基于 Nginx 与 Lua 的高性能 Web 平台,其内部集成了大量精良的 Lua 库、第三方模块以及大多数的依赖项。用于方便地搭建能够处理超高并发、扩展性极高的动态 Web 应用、Web 服务和动态网关。

OpenResty 官方 APT 包仓库提供了 deb 包 (适用于 Ubuntu 和 Debian),可以很方便的安装,一起来看下具体的安装步骤吧。

Debian 更新系统

?
1
2
3
$ apt update
# 这一步选做
$ apt upgrade

添加 openresty 仓库

可以在 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

到此这篇关于在Debian11上安装Openresty服务(Nginx+Lua)的文章就介绍到这了,更多相关Debian安装Openresty服务内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文链接:https://www.cnblogs.com/wangyongtao/p/16802986.html

声明: 猿站网有关资源均来自网络搜集与网友提供,任何涉及商业盈利目的的均不得使用,否则产生的一切后果将由您自己承担! 本平台资源仅供个人学习交流、测试使用 所有内容请在下载后24小时内删除,制止非法恶意传播,不对任何下载或转载者造成的危害负任何法律责任!也请大家支持、购置正版! 。本站一律禁止以任何方式发布或转载任何违法的相关信息访客发现请向站长举报,会员发帖仅代表会员个人观点,并不代表本站赞同其观点和对其真实性负责。本网站的资源部分来源于网络,如有侵权烦请发送邮件至:2697268773@qq.com进行处理。
建站知识

小知识:nginx报502错误怎么排查?nginx 502 bad gateway错误排查思路

2023-3-14 1:05:34

建站知识

小知识:Nginx gateway集群和动态网关的实现思路

2023-3-14 1:24:16

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索