一、介绍:
- OpenResty®是一个基于 Nginx 与 Lua 的高性能 Web 平台,其内部集成了大量精良的 Lua 库、第三方模块以及大多数的依赖项。用于方便地搭建能够处理超高并发、扩展性极高的动态 Web 应用、Web 服务和动态网关。
- OpenResty通过汇聚各种设计精良的 Nginx 模块,从而将 Nginx 有效地变成一个强大的通用 Web 应用平台。这样,Web 开发人员和系统工程师可以使用 Lua 脚本语言调动 Nginx 支持的各种 C 以及 Lua 模块,快速构造出足以胜任 10K 乃至 1000K 以上单机并发连接的高性能 Web 应用系统。
- OpenResty 的目标是让你的Web服务直接跑在 Nginx 服务内部,充分利用 Nginx 的非阻塞 I/O 模型,不仅仅对 HTTP 客户端请求,甚至于对远程后端诸如 MySQL、PostgreSQL、Memcached 以及 Redis 等都进行一致的高性能响应。
二、docker 安装
2.1、创建挂载目录
mkdir -p /home/docker/openresty/nginx
mkdir -p /home/docker/openresty/nginx/lua
mkdir -p /home/docker/openresty/nginx/logs
2.2、拉去镜像
docker pull openresty/openresty
2.3、运行OpenResty容器拷贝一些配置文件
# 运行openresty容器
docker run -d --name openresty -p 7000:80 openresty/openresty
2.4、拷贝文件夹内容到宿主机
docker cp openresty:/usr/local/openresty/nginx/conf /home/docker/openresty/nginx/conf
docker cp openresty:/usr/local/openresty/nginx/html /home/docker/openresty/nginx/html
docker cp openresty:/etc/nginx/conf.d /home/docker/openresty/nginx/conf.d
2.5、停止并删除容器
docker stop openresty
docker rm openresty
2.6、修改配置
可以在 /home/docker/openresty/nginx/conf.d 文件夹下新建自己的配置文件(openresty默认加载此文件下的所有配置文件)
例:以下是示例文件(注意:这里的配置和nginx基本一样,当然在这里可以执行lua脚本)
upstream siyu{
server ip:port weight=1;
}
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
proxy_pass http://siyu;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/local/openresty/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root /usr/local/openresty/nginx/html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
2.7、启动容器
docker run -d \
--privileged=true \ #容器将以特权模式运行。容器内的进程将拥有与宿主机上的root用户相似的权限
--restart=always \ #无论容器是正常退出还是异常退出,Docker都会自动重启该容器。
--name openresty \
-p 80:80 \
-p 8000:8000 \
-v /home/docker/openresty/nginx/conf:/usr/local/openresty/nginx/conf/:rw \
-v /home/docker/openresty/nginx/conf.d:/etc/nginx/conf.d/:rw \
-v /home/docker/openresty/nginx/html:/usr/local/openresty/nginx/html/:rw \
-v /home/docker/openresty/nginx/logs:/usr/local/openresty/nginx/logs/:rw \
-v /home/docker/openresty/nginx/lua:/usr/local/openresty/nginx/lua/:rw \
openresty/openresty
然后访问 服务器的80端口你会看到你自己代理的服务,当然如果没配置代理会看到以下页面(记得开放端口
)
三、结语
到这里,openresty的安装就结束了!至于他的使用,以及lua脚本,我们会在新版微服务项目搭建中详细介绍 添加链接描述
明天的你一定会感谢今天努力的自己,加油!!!