• Geek_144c1d
    2019-05-29
    先将代码打包成`.lua` 文件
    使用配置文件指令 `content_by_lua_file` 引用
    类库代码 如果有 reqiure 的需求
    可利用 `lua_package_path` 和 `lua_package_cpath` 设定类库加载目录

    作者回复: 👍

    
     18
  • cylim
    2019-05-29
    既然是基础课,应该提醒我们关闭server。
    openresty -s quit -p `pwd` -c conf/nginx.conf


    把lua代码写在其他文件上,然后带入nginx.conf使用。

    作者回复: 欢迎补充:)

    
     8
  • helloworld
    2019-06-21
    编译安装PART1:
    老师说的对,对于大多数项目来说都没有必要自己折腾编译安装,费时费力。不过有时候自己动手编译安装也是必须的,因为根据具体项目的需要,比如CDN项目,官方的默认编译选项就缺少一些必要的模块,比如ngx_cache_purge模块,如果需要对ipv6做支持,还需要nginx的--with-ipv6编译选项,等等。下面是我根据官方打包文件总结的centos平台下编译安装最新版本的openresty具体流程。centos6下完美运行,7也应该不是问题。给各位小伙伴在需要的时候参考,少走弯路,节省宝贵时间。
    # 安装 pcre
    wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.42.tar.bz2
    tar xjf pcre-8.42.tar.bz2
    cd pcre-8.42
     ./configure --prefix=/usr/local/openresty/pcre \
     --disable-cpp --enable-jit \
     --enable-utf --enable-unicode-properties
    make -j24 V=1 > /dev/stderr
    make install

    rm -rf /usr/local/openresty/pcre/bin
    rm -rf /usr/local/openresty/pcre/share
    rm -f /usr/local/openresty/pcre/lib/*.la
    rm -f /usr/local/openresty/pcre/lib/*pcrecpp*
    rm -f /usr/local/openresty/pcre/lib/*pcreposix*
    rm -rf /usr/local/openresty/pcre/lib/pkgconfig

    # 安装zlib
    cd /usr/local/src
    wget http://www.zlib.net/zlib-1.2.11.tar.xz
    tar xf zlib-1.2.11.tar.xz
    cd zlib-1.2.11
     ./configure --prefix=/usr/local/openresty/zlib
    make -j24 \
    CFLAGS='-O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -g' \
    SFLAGS='-O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -g' > /dev/stderr
    make install
    rm -rf /usr/local/openresty/zlib/share/
    rm -f /usr/local/openresty/zlib/lib/*.la
    rm -rf /usr/local/openresty/zlib/lib/pkgconfig/

    # 安装openssl
    cd /usr/local/src
    wget https://www.openssl.org/source/openssl-1.1.0j.tar.gz
    wget https://raw.githubusercontent.com/openresty/openresty/master/patches/openssl-1.1.0d-sess_set_get_cb_yield.patch --no-check-certificate
    wget https://raw.githubusercontent.com/openresty/openresty/master/patches/openssl-1.1.0j-parallel_build_fix.patch --no-check-certificate
    tar zxf openssl-1.1.0j.tar.gz
    cd openssl-1.1.0j
    继续见PART2
    展开

    作者回复: 👍

    
     5
  • aaron
    2019-05-30
    我使用yum安装了openresty之后并没有resty工具,我也没发现-p 'pwd'的意义何在,-c nginx.conf也启动不起来,最后我是用openresty -c /opt/geektime/conf/nginx.conf启动的。。。

    作者回复: centos 下需要单独安装:sudo yum install openresty-resty

     2
     5
  • 业余草
    2019-05-29
    content_by_lua指令看起来非常怪!没有用{}

    作者回复: 嗯,可以用 content_by_lua_block

    
     3
  • helloworld
    2019-06-21
    编译安装PART3:
    # 最后开始编译安装openresty
    cd /usr/local/src
    wget https://openresty.org/download/openresty-1.15.8.1.tar.gz # 如果下载出现ssl报错,yum update wget,再下载
    tar zxf openresty-1.15.8.1.tar.gz
    cd openresty-1.15.8.1
    ./configure \
        --prefix=/usr/local/openresty \
        --with-cc-opt="-DNGX_LUA_ABORT_AT_PANIC \
                    -I/usrl/local/openresty/zlib/include \
                    -I/usr/local/openresty/pcre/include \
                    -I/usr/local/openresty/openssl/include" \
        --with-ld-opt="-L/usr/local/openresty/zlib/lib \
                    -L/usr/local/openresty/pcre/lib \
                    -L/usr/local/openresty/openssl/lib \
                    -Wl,-rpath,/usr/local/openresty/zlib/lib:/usr/local/openresty/pcre/lib:/usr/local/openresty/openssl/lib" \
        --with-pcre-jit \
        --without-http_rds_json_module \
        --without-http_rds_csv_module \
        --without-lua_rds_parser \
        --with-stream \
        --with-stream_ssl_module \
        --with-stream_ssl_preread_module \
        --with-http_v2_module \
        --without-mail_pop3_module \
        --without-mail_imap_module \
        --without-mail_smtp_module \
        --with-http_stub_status_module \
        --with-http_realip_module \
        --with-http_addition_module \
        --with-http_auth_request_module \
        --with-http_secure_link_module \
        --with-http_random_index_module \
        --with-http_gzip_static_module \
        --with-http_sub_module \
        --with-http_dav_module \
        --with-http_flv_module \
        --with-http_mp4_module \
        --with-http_gunzip_module \
        --with-threads \
        --with-luajit-xcflags='-DLUAJIT_NUMMODE=2 -DLUAJIT_ENABLE_LUA52COMPAT' \
        -j24
    make -j24
    make install

    rm -rf /usr/local/openresty/luajit/share/man
    rm -rf /usr/local/openresty/luajit/lib/libluajit-5.1.a

    [END]
    展开
    
     2
  • helloworld
    2019-06-21
    编译安装PART2:
    patch -p1 < ../openssl-1.1.0d-sess_set_get_cb_yield.patch
    patch -p1 < ../openssl-1.1.0j-parallel_build_fix.patch
    ./config \
        no-threads shared zlib -g \
        enable-ssl3 enable-ssl3-method \
        --prefix=/usr/local/openresty/openssl \
        --libdir=lib \
        -I%/usr/local/openresty/zlib/include \
        -L%/usr/local/openresty/zlib/lib \
        -Wl,-rpath,/usr/local/openresty/zlib/lib:/usr/local/openresty/openssl/lib
    make -j24
    make install_sw

    rm -f /usr/local/openresty/openssl/bin/c_rehash
    rm -rf /usr/local/openresty/openssl/lib/pkgconfig

    继续见PART3
    展开
    
     2
  • One、Two、Three
    2019-06-15
    老师好,有个问题请教一下
    openresty -v
    nginx version: openresty/1.15.8.1
    which openresty
    /usr/local/bin/openresty
    which resty
    /usr/local/bin/resty
    这些都没问题
    which luajit
    luajit not found
    luajit为什么没有呢
    展开

    作者回复: luajit 的可执行文件并没有被拷贝到/usr/local/bin目录下,所有找不到。这个是为了避免了已经安装的 luajit 冲突,毕竟 OpenResty 自带的 LuaJIT 是自己维护的版本

    
     2
  • 回家
    2019-06-04
    温铭老师好,假设操作系统中已经安装openssl/pcre/zlib,使用openresty的仓库地址,然后使用包管理器安装openresty,这个时候操作系统里有几个openssl/pcre/zlib呢?只有一个的话,是不是openresy维护的openssl/pcre/zlib?如果是的话,升级或者说安装操作系统中的更新版本的openssl(不是升级openresy维护的openssl),能否升级成功呢?如果升级成功,openresty执行的时候是否会出错呢?

    作者回复: openresty 维护的 openssl/pcre/zlib 都会安装在 /usr/local/openresty/ 目录下,并不会冲突。

    
     2
  • moshufenmo
    2019-05-29
    请问老师,开发openresty使用什么IDE? 一直在用sublime,但是lua文件一多,相互间引用关系就很难查看

    作者回复: 没有什么特别好用的,我用的是微软的 vscode

    
     2
  • 天天向上
    2019-05-29
    mac brew安装貌似很费劲 网上很多方法都报错

    作者回复: brew 安装也需要先指定 OpenResty 的仓库地址,具体请查看openresty.org 的文档

    
     2
  • MOIC💅
    2020-02-05
    openresty -p `pwd` -c ./conf/nginx.conf 启动
    openresty -p `pwd` -c ./conf/nginx.conf -s stop 停止
    lsof -i:端口号 查看服务状态
    
     1
  • 回家
    2019-06-04
    温铭老师,你好,有读者问vscode有没有openresty扩展,你说你用的lua扩展,这个是什么意思呢?还有老师你用的是什么IDE呀?

    作者回复: 我用的是 vs code,用的是 lua 和 luacheck 两个插件

    
     1
  • Run
    2020-01-10
    最近要为公司的Kong开发插件,需要动态创建更新几千条service,router,customer,还特么是并发场景,Kong本身没有批量创建的API,只能手动撸插件加队列了
    
    
  • 曹峰
    2019-10-23
    老师,mac最新系统 10.15 无法安装 openresty , https://github.com/openresty/homebrew-brew/issues/10
     1
    
  • 阿柒
    2019-10-10
    老师那个ngx这个全局变量是谁提供的,怎么来的啊?
    
    
  • void
    2019-10-04
    老师,我也是用的mac vscode 装了luacheck。然后lua脚本里写ngx.say的时候,底下命令行窗口就会报一句:accessing undefined variable `ngx` luacheck[1,1] 。当然实际上 能运行,但是就是一直报这句,看着有点强迫症受不了。搜了好久也没找到解决方案,不知道老师用vscode的时候 会不会报这个,是如何解决的?
    
    
  • 程斌
    2019-07-22
    最近工作也用到这个工具了。特地买了教程来学习,谢谢老师。这个是我的学习笔记,会一步一步的跟着老师脚步做好笔记。https://www.iffor.cn/tech/openresty-install.html

    作者回复: 👍 总结之后的才是自己的知识

    
    
  • 在下不恭
    2019-07-08
    老师您好,安装完openresty以后,执行which resty 提示: no resty in (/usr/local/msp/runtime/jre-8u131-linux-x64/bin:/usr/local/msp/runtime/jre-8u131-linux-x64/jre/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)

    作者回复: 你那边是什么操作系统?使用什么方式安装的呢?如果使用 rpm 安装的话,是会有的,可以从这里看到:https://github.com/openresty/openresty-packaging/blob/master/rpm/SPECS/openresty.spec#L233

    
    
  • Leon📷
    2019-07-03
    已经解决了,新版的openresty的nginx依赖ssl1.1,所以启动不起来,我看了access log 然后编译了ssl1.1的动态库放在lib64下就好了,这个其他同学也可以参考下

    作者回复: 1.15.8 里面是依赖 openssl 1.1 的,所以尽量用 rpm 之类方式来处理

    
    
我们在线,来聊聊吧