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

相關文章
相關標籤/搜索