首先下载最新的openresty
wget http://openresty.org/download/ngx_openresty-1.7.10.1.tar.gz
接下来开始安装带lua模块的openresty
./configure --prefix=/home/app/ngx_openresty-1.7.7.7.2 --with-luajit --with-pcre=/home/download/pcre-7.8
安装redis
下载redis3.0
wget http://download.redis.io/releases/redis-3.0.0.tar.gz
make install
然后配置一下nginx配置
nginx.conf
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log main;
sendfile on;
keepalive_timeout 65;
gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
access_log logs/host.access.log main;
location / {
# root html;
# index index.html index.htm;
proxy_pass http://sonicery_d.com;
}
location /syd{
proxy_pass http://sonicery_d.com;
}
location /hello{
root html;
}
location /testlua{
default_type text/plain;
content_by_lua_file /home/app/lua/test.lua;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
include upstream.conf;
}
test.lua
local redis = require "resty.redis"
local cache = redis.new()
cache.connect(cache,'127.0.0.1',6379)
local res = cache:get("foo")
if res == ngx.null then
ngx.say("This is null")
return
end
ngx.say(res)