安装
- 添加官方软件包到yum中
yum install yum-utils
yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo
- 安装OpenResty
yum install openresty
- 安装OpenResty 的 CLI工具
yum install openresty-resty
-
检验
image.png
hello world
- 使用resty -e 执行命令
resty -e 'print("hello, world")'
OpenResty
OpenResty 使用三部曲
- 创建工作目录
mkdir ~/work
cd ~/work
mkdir logs/ conf/
- 准备 NGINX 的配置文件, 在文件中嵌入Lua代码
vim conf /nginx.conf
worker_processes 1;
error_log logs/error.log;
events {
worker_connections 1024;
}
http {
server {
listen 8080;
location / {
content_by_lua_block {
ngx.say("<p>hello, world</p>")
}
}
}
}
- 启动 OpenResty 服务
openresty -p `pwd` -c conf/nginx.conf
- 检验
curl -i 127.0.0.1:8080
netstat -tpnl

- 关闭服务
openresty -s quit -p `pwd` -c conf/nginx.conf

或者
sudo kill -HUP `cat logs/nginx.pid`
附加
- 安装OpenResty doc工具
yum install restydoc
- 使用文档工具
restydoc -s ngx.say

网友评论