Created
November 2, 2012 03:04
Revisions
-
moonming created this gist
Nov 2, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ worker_processes 1; events { worker_connections 64; } http { send_timeout 1s; server_tokens off; client_body_buffer_size 128k; upstream database { postgres_server localhost:5432 dbname=test user=adminpassword=test123; postgres_keepalive max=80 mode=single overflow=ignore; } lua_package_path "$prefix/?.luac;$prefix/?.lua;;"; include mime.types; log_format access '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent $request_time $request_body'; include ngx_php_win.conf; include ngx_lua_win.conf; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ server { listen 80; access_log off;#/var/log/nginx/access.log access; gzip on; gzip_types text/plain application/x-javascript text/css application/xml; location /postgres { internal; default_type text/html; set_by_lua $query_sql 'return ngx.unescape_uri(ngx.var.arg_sql)'; postgres_pass database; rds_json on; postgres_query $query_sql; } location /hello { access_log off; default_type text/html; content_by_lua ' ngx.say("<p>hello, world</p>") '; } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ function query_from_db(sql) local res = ngx.location.capture('/postgres', { args = {sql = sql } } ) local status = res.status local body = json.decode(res.body) if status == 200 then status = true else status = false end return status, body end function client_heartbeat(mid) common.query_from_db("BEGIN") local sql = [[UPDATE clients SET update_time = now() WHERE midn = ']] .. mid .. [[']] common.query_from_db(sql) common.query_from_db("COMMIT") end