openresty lua學習筆記

一、環境搭建

不多說,參考官方文檔

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

某些模塊沒有加載的自行看文檔是否默認加載,沒有的話加進去

http://openresty.org/cn/

nginx針對lua的配置參數及API文檔參考(重要,異步非阻塞,能用ngx儘量就別用Lua的api)  

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

二、nginx.conf配置說明

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;
        }
    }
}

三、附件是測試時用到的模塊和測試文件,記得下載後後綴改爲lua

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章