简介
OpenResty 可以直接使用Lua
脚本编写复杂的逻辑运行在Nginx
之上,可以做很多好玩的应用,快速构造出足以胜任10K
乃至1000K
以上单机并发连接的高性能Web
应用系统。
环境:
机型: 1核 1GB 1Mbps 腾讯云服务器
系统: CentOS Linux release 8.4.2105 (Core)
注意:需要预先安装docker
、docker-compose
服务。
部署步骤
创建挂载目录
1
mkdir -p openresty/{conf.d,logs}
准备镜像
- 打开Dock Hub搜索
openresty
- 下载官方镜像,命令:
docker pull openresty/openresty:alpine
编写 docker-compose.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15version: '3'
services:
openresty:
image: openresty/openresty:alpine
restart: always
volumes:
- $PWD/logs:/usr/local/openresty/nginx/logs
- $PWD/conf.d/:/etc/nginx/conf.d
ports:
- "8080:80"
networks:
- appnet
networks:
appnet:启动openresty
1
docker-compose up -d
测试是否成功
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29curl http://localhost:8080
<!DOCTYPE html>
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<title>Welcome to OpenResty!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to OpenResty!</h1>
<p>If you see this page, the OpenResty web platform is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to our
<a href="https://openresty.org/">openresty.org</a> site<br/>
Commercial support is available at
<a href="https://openresty.com/">openresty.com</a>.</p>
<p>We have articles on troubleshooting issues like <a href="https://blog.openresty.com/en/lua-cpu-flame-graph/?src=wb">high CPU usage</a> and
<a href="https://blog.openresty.com/en/how-or-alloc-mem/">large memory usage</a> on <a href="https://blog.openresty.com/">our official blog site</a>.
<p><em>Thank you for flying <a href="https://openresty.org/">OpenResty</a>.</em></p>
</body>
</html>按照Openresty文档进行测试
- 在
conf.d
文件夹中创建nginx.conf
配置1
2
3
4
5
6
7
8
9server {
listen 80;
location / {
default_type text/html;
content_by_lua '
ngx.say("<p>hello, world</p>")
';
}
} - 重启
docker-compose
1
docker-compose restart
- 验证
1
2curl http://localhost:8080
<p>hello, world</p>
总结
- 注意容器里的时区不是正确的, 如要修正可参考《修改基于 alpine 系统的 Docker 镜像时区配置》
Done.