CentOS7安装OpenResty

本文介绍如何在CentOS7上安装OpenResty,一个基于Nginx和Lua的高性能Web平台,适用于搭建高并发动态Web应用。遵循官方下载地址,安装依赖库,编译并配置启动服务,通过systemctl进行管理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

有一个项目是Lua库写的,需要部署一个web服务器,考虑Openresty对lua的支持,部署Openresty。

OpenResty

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

下载地址:

  1. 安装依赖库:
$ yum install -y pcre-devel openssl-devel gcc curl
  1. 下载版本:
$ wget https://openresty.org/download/openresty-1.15.8.1.tar.gz
  1. 解压:
$ tar -xzvf openresty-1.15.8.1.tar.gz
  1. 进入解压目录:
$ cd openresty-1.15.8.1/
  1. 检查配置环境, 生成 Makefile,默认安装到/usr/local/openresty:
$ ./configure
  1. 编译安装:
$ gmake && gmake install

安装结果:

mkdir -p /usr/local/openresty/site/lualib /usr/local/openresty/site/pod /usr/local/openresty/site/manifest
ln -sf /usr/local/openresty/nginx/sbin/nginx /usr/local/openresty/bin/openresty

可以看到openresty 实际上是nginx的软连接。

  1. 查看版本号:
$ /usr/local/openresty/bin/openresty -v
nginx version: openresty/1.15.8.3
  1. 启动:
检验配置
/usr/local/openresty/bin/openresty -t
启动
/usr/local/openresty/bin/openresty
停止
/usr/local/openresty/bin/openresty -s stop
重新加载配置
/usr/local/openresty/bin/openresty -s reload
  1. 配置/lib/systemd/system/openresty.service,通过systemctl启动:
[Unit]
Description=openresty - high performance web server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
ExecStart=/usr/local/openresty/bin/openresty -c /usr/local/openresty/nginx/conf/nginx.conf
ExecReload=/usr/local/openresty/bin/openresty -s reload
ExecStop=/usr/local/openresty/bin/openresty -s stop

[Install]
WantedBy=multi-user.target

添加openresty.service后,使配置文件生效:

$ systemctl daemon-reload

然后,就可以使用systemctl管理openresty:

启动
$ systemctl start openresty
停止
$ systemctl stop openresty
重载配置
$ systemctl reload openresty
重启
$ systemctl restart openresty
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值