openresty lua学习笔记

1、环境搭建html

很少说,参考官方文档nginx

https://moonbingbing.gitbooks.io/openresty-best-practices/content/lua/build_env.htmlgit

某些模块没有加载的自行看文档是否默认加载,没有的话加进去redis

http://openresty.org/cn/sql

nginx针对lua的配置参数及API文档参考(重要,异步非阻塞,能用ngx尽可能就别用Lua的api)  数据库

https://www.nginx.com/resources/wiki/modules/lua/#ngx-execjson

2、nginx.conf配置说明api

worker_processes  1;        #nginx worker 数量
error_log logs/error.log;   #指定错误日志文件路径
events {
    worker_connections 1024;
}
http {
    upstream pg_server { #pgsql数据库配置
        postgres_server 192.168.180.130:5432 dbname=hzctmsg user=postgres password=postgres;
        postgres_keepalive max=800 mode=single overflow=reject;
    }
    server {
        #监听端口,若你的6699端口已经被占用,则须要修改
        listen 6699;
        keepalive_timeout 20; #长链接timeout
        keepalive_requests 8192; #每一个链接最大请求数
        lua_code_cache off;#不用重启nginx,lua代码修改当即生效,测试时能够试用,生产要关闭
        location / {
            default_type text/html;
            content_by_lua_file /openresty-work/lua/test_redis_pgsql.lua;
        }
        location /postgres {
            internal;
            default_type text/html;
            set_by_lua $query_sql 'return ngx.unescape_uri(ngx.var.arg_sql)';
            postgres_pass   pg_server;#关联上面的upstream...
            rds_json          on;
            rds_json_buffer_size 16k;
            postgres_query  $query_sql;
            postgres_connect_timeout 1s;
            postgres_result_timeout 2s;
        }
    }
}

3、附件是测试时用到的模块和测试文件,记得下载后后缀改成lua
bash

相关文章
相关标签/搜索