- Macbook官网推荐的安装方法是通过Homebrew,具体查看链接 https://openresty.org/cn/installation.html
- 如果通过Homebrew安装出现问题,可以尝试以下二进制包安装方式
- 下载二进制包 https://openresty.org/cn/download.html,下载对应版本的 .tar.gz 文件, tar -zxvf xx.tar.gz 解压缩并cd进入
- 安装依赖 brew install pcre openssl
- 修改配置 ./configure
–with-cc-opt="-I/usr/local/opt/openssl/include/ -I/usr/local/opt/pcre/include/" –with-ld-opt="-L/usr/local/opt/openssl/lib/ -L/usr/local/opt/pcre/lib/" -j4 可以加 --prefix=/opt/openresty 参数指定安装目录,默认可能是/usr/local/ -j4 表示开启4个核心,可以自定义数量 - make -j4
- sudo make install
- 修改环境变量
export PATH=$PATH:/usr/local/openresty/nginx/sbin:/usr/local/openresty/bin - 测试
mkdir /home/test/work
cd /home/test/work
mkdir conf/ logs/
vim conf/nginx.conf
worker_processes 1;
error_log logs/error.log;
events {
worker_connections 1024;
}
http {
server {
listen 8080;
location / {
default_type text/html;
content_by_lua_block {
ngx.say("<p>hello, world</p>")
}
}
}
}
nginx -p `pwd`/ -c conf/nginx.conf
curl http://localhost:8080/
nginx -p `pwd`/ -s reload
server下添加 lua_code_cache off; 配置 生产环境一定要打开缓存,否则会很影响性能
mkdir lua/hello.lua
vim lua/hello.lua
输入ngx.say("hello world with lua file")
修改nginx.conf
location /hello{
default_type text/html;
content_by_lua_file lua/hello.lua;
}
location / { ....
重启nginx
curl http://localhost:8080/hello
参考链接
https://openresty.org/cn/installation.html https://openresty.org/en/getting-started.html https://openresty.org/cn/download.html
|