OpenResty Macbook安装

  1. Macbook官网推荐的安装方法是通过Homebrew,具体查看链接 https://openresty.org/cn/installation.html
  2. 如果通过Homebrew安装出现问题,可以尝试以下二进制包安装方式
  3. 下载二进制包 https://openresty.org/cn/download.html,下载对应版本的 .tar.gz 文件, tar -zxvf xx.tar.gz 解压缩并cd进入
  4. 安装依赖 brew install pcre openssl
  5. 修改配置 ./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个核心,可以自定义数量
  6. make -j4
  7. sudo make install
  8. 修改环境变量
    export PATH=$PATH:/usr/local/openresty/nginx/sbin:/usr/local/openresty/bin
  9. 测试
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
nginx -p `pwd`/ -s reload
# 修改nginx.conf文件立即生效
server下添加 lua_code_cache off; 配置 生产环境一定要打开缓存,否则会很影响性能
# 单独运行lua文件
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

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值