http://blog.csdn.net/guoyuguang0/article/details/76768924
http://blog.51cto.com/haoyun/1135166
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
root html;
index index.html index.htm;
location / {
content_by_lua '
local mysql = require "resty.mysql"
local db,err = mysql:new()
if not db then
ngx.say("failed to instantiate mysql: ",err)
return
end
db:set_timeout(1000)
local ok,err,errno,sqlstate = db:connect{
host = "127.0.0.1",
port = 3306,
database = "test",
user = "root",
password = "",
max_package_size = 1024
}
if not ok then
ngx.say("failed to connect: ", err, ": ", errno, " ", sqlstate)
return
end
res,err,errno,sqlstate = db:query("select id,username,age from users where id=1")
if not res then
ngx.say("bad result: ", err, ": ", errno, ": ", sqlstate, ".")
return
end
local cjson = require "cjson"
ngx.say(cjson.encode(res))
';
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}