OpenResty 是一个基于 Nginx 与 Lua 的高性能 Web 平台,其内部集成了大量精良的 Lua 库、第三方模块以及大多数的依赖项。用于方便地搭建能够处理超高并发、扩展性极高的动态 Web 应用、Web 服务和动态网关。
官方中文网站https://openresty.org/cn/
官方Github https://github.com/openresty/openresty
安装
Linux
安装参考https://openresty.org/cn/linux-packages.html,例如Ubuntu安装方式如下
# 安装导入 GPG 公钥时所需的几个依赖包(整个安装过程完成后可以随时删除它们):sudo apt-get -y install --no-install-recommends wget gnupg ca-certificates# 导入我们的 GPG 密钥:wget -O - https://openresty.org/package/pubkey.gpg | sudo apt-key add -# 安装 add-apt-repository 命令# (之后你可以删除这个包以及对应的关联包)sudo apt-get -y install --no-install-recommends software-properties-common# 添加我们官方 official APT 仓库:sudo add-apt-repository -y "deb http://openresty.org/package/ubuntu $(lsb_release -sc) main"# 更新 APT 索引:sudo apt-get update然后就可以像下面这样安装软件包,比如 openresty:sudo apt-get -y install openresty
macOS
推荐使用brew
brew install openresty/brew/openresty
启动方式
To have launchd start openresty/brew/openresty now and restart at login:brew services start openresty/brew/openrestyOr, if you don't want/need a background service you can just run:openresty
docker
官方地址https://github.com/openresty/docker-openresty
$ docker run -d --name openresty -p80:80 openresty/openresty
访问http://localhost/
如果需要配置自定义的docker-compose
version: "3.7"services:web:image: openresty/openrestycontainer_name: openrestyports:- "80:80"volumes:- ./nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf
默认的配置文件
worker_processes auto;events {worker_connections 1024;}http {include mime.types;default_type application/octet-stream;# See Move default writable paths to a dedicated directory (#119)# https://github.com/openresty/docker-openresty/issues/119client_body_temp_path /var/run/openresty/nginx-client-body;proxy_temp_path /var/run/openresty/nginx-proxy;fastcgi_temp_path /var/run/openresty/nginx-fastcgi;uwsgi_temp_path /var/run/openresty/nginx-uwsgi;scgi_temp_path /var/run/openresty/nginx-scgi;sendfile on;keepalive_timeout 65;include /etc/nginx/conf.d/*.conf;}
helloworld
修改配置文件如下
events {worker_connections 1024;}http {server {listen 80;location / {content_by_lua 'ngx.say("hello, lua")';}}}
$ curl -i 127.0.0.1:80HTTP/1.1 200 OKServer: openresty/1.15.8.2Date: Sat, 07 Mar 2020 10:04:07 GMTContent-Type: text/plainTransfer-Encoding: chunkedConnection: keep-alivehello, lua
