openresty简单部署,openresty部署




openresty安装:
1、下载openresty安装包及依赖包
http://openresty.org/cn/download.html
目前最新版本: openresty-1.11.2.5.tar.gz

依赖包:
pcre-8.41.tar.gz  http://www.pcre.org/
zlib-1.2.11.tar.gz    http://www.zlib.net/
openssl-1.0.2m.tar.gz   https://www.openssl.org/
2、上传压缩包到主机
   解压  tar xvf openresty-1.11.2.5.tar.gz
         tar xvf pcre-8.41.tar.gz
         tar xvf zlib-1.2.11.tar.gz
         tar xvf openssl-1.0.2m.tar.gz
        
3、安装openresty
   cd openresty-1.11.2.5
   ./configure --prefix=/crmpdpp/sgwadm/work/zhangtaoa/nginx/myng --without-http_redis2_module  --with-http_iconv_module --with-pcre=/crmpdpp/sgwadm/work/zhangtaoa/nginx/pcre-8.41 --with-zlib=/crmpdpp/sgwadm/work/zhangtaoa/nginx/zlib-1.2.11 --with-openssl=openssl-1.0.2m
  
   pcre、zlib、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/"
   pcre、openssl指定的是安装完后的include、lib目录
  
   注:在 1.5.8.1 版本之前, OpenResty 默认使用标准 Lua 5.1 解释器。所以对于老版本, 你需要显式地加入--with-luajit 编译选项(1.5.8.1 以后的版本已默认开启)来启用 LuaJIT 组件。
  
4、启动
   cd nginx/sbin
   nginx
  
5、修改配置文件
   server {
        listen       20004;   ----监听端口,默认是80
       
   url配置
  
   location ~ /test001/(\d+) {
               set $test "zhangtao";
               set $a $1;
               set $b $host;
               content_by_lua 'ngx.say(ngx.var.b)';
        }
       
6、重启nginx
   nginx -s reload
  
7、测试
   curl http://127.0.0.1:20004/test0001/1
  
   返回
   1
  
8、官网提供的redis操作样例
    server {
        listen       20004;
        server_name  test.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location ~ /test001/(\d+) {
               set $test "zhangtao";
               set $a $1;
               set $b $host;
               content_by_lua 'ngx.say(ngx.var.b)';
        }
       
        location = /redis {
            internal;
            set_unescape_uri $key $arg_key;
            redis2_query get $key;
            redis2_pass 127.0.0.1:6379;
        }

        location /myredis {
            set $target '';
            access_by_lua '
                local key = ngx.var.arg_name
                local res = ngx.location.capture(
                    "/redis", { args = { key = key } }
                )
               
                if res.status ~= 200 then
                    ngx.log(ngx.ERR, "redis server returned bad status: ",
                        res.status)
                    ngx.exit(res.status)
                end
               
                if not res.body then
                    ngx.log(ngx.ERR, "redis returned empty body")
                    ngx.exit(500)
                end
               
                local parser = require "redis.parser"
                local server, typ = parser.parse_reply(res.body)
                if typ ~= parser.BULK_REPLY or not server then
                    ngx.exit(500)
                end
               
                ngx.var.target = server
            ';
           
            echo $target;
        }

相关内容

    暂无相关文章