Linux安装OpenResty

本文详细指导了在Linux CentOS 7环境中安装OpenResty的过程,包括依赖库安装、源码下载、配置Makefile并编译安装,以及后续的启动、停止、检查和系统集成。重点介绍了如何通过systemd进行服务管理和查看版本。

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

说明

Linux 是Centos7

安装

依次执行下面的命令:

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

安装完了显示

gmake[2]: 离开目录“/root/openresty-1.15.8.1/build/nginx-1.15.8”
gmake[1]: 离开目录“/root/openresty-1.15.8.1/build/nginx-1.15.8”
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
[root@zjj101 openresty-1.15.8.1]#

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

查看版本号

[root@zjj101 openresty-1.15.8.1]# /usr/local/openresty/bin/openresty -v
nginx version: openresty/1.15.8.1

默认安装位置

安装完了openresty之后Nginx默认的位置是:

/usr/local/openresty/nginx

启动停止

下面的命令根据需求去执行

# 检验配置
/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

查看进程是否启动

[root@zjj101 openresty-1.15.8.1]# ps -ef|grep openresty
root     106088      1  0 19:07 ?        00:00:00 nginx: master process /usr/local/openresty/bin/openresty
root     106131  96410  0 19:08 pts/0    00:00:00 grep --color=auto openresty

浏览器访问

http://172.16.10.101/

访问完了能在页面看到这些字就说明启动成功了.

Welcome to OpenResty!
If you see this page, the OpenResty web platform is successfully installed and working. Further configuration is required.

For online documentation and support please refer to openresty.org.
Commercial support is available at openresty.com.

Thank you for flying OpenResty.

配置/lib/systemd/system/openresty.service,通过systemctl启动:

vim /lib/systemd/system/openresty.service

[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 status openresty.service
停止 
 systemctl stop openresty
重载配置
 systemctl reload openresty
重启
 systemctl restart openresty

参考

https://blog.csdn.net/yisangwu/article/details/106728595

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值