支离书's Blog

输出倒逼输入,赚钱治愈矫情

0%

Mac下OpenRestry安装和使用

一、安装

  • 下载源码包,解压,并进入到解压目录
  • 执行下面的命令编译
    1
    ./configure --prefix=/opt/openresty --with-cc-opt="-I/usr/local/Cellar/pcre/8.36/include" --with-luajit --without-http_redis2_module --with-ld-opt="-L/usr/local/Cellar/pcre/8.36/lib" --with-openssl="bundle/openssl-1.0.2d" -j2

过程中遇到三个问题:

  1. pcre的路径要找对;
  2. Xcode如果装了多个版本,需要使用sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer选择到最新的版本
  3. openssl,下了最新的1.0.2e的源码不行,换成1.0.2d就可以了,不知为什么
  • 执行make和sudo make install

    二、HelloWorld

  • 创建工作目录
    1
    2
    3
    mkdir ~/work
    cd ~/work
    mkdir logs/ conf/
  • 创建conf/nginx.conf
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    worker_processes  1;
    error_log logs/error.log;
    events {
    worker_connections 1024;
    }
    http {
    server {
    listen 8080;
    location / {
    default_type text/html;
    content_by_lua '
    ngx.say("<p>hello, world</p>")
    ';
    }
    }
    }
  • 启动nginx
    • 设置nginx的目录到环境变量中 PATH=/opt/openresty/nginx/sbin:$PATH export PATH
    • 启动nginx,在work目录下执行 nginx -p pwd/ -c conf/nginx.conf
  • 验证 curl http://localhost:8080/
    • 输出 <p>hello, world</p>

欢迎关注我的其它发布渠道