爱在莫斯科 发表于 2016-12-20 06:04:11

构建nginx lua redis高并发应用

  首先下载最新的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

#usernobody;
worker_processes1;
#error_loglogs/error.log;
#error_loglogs/error.lognotice;
#error_loglogs/error.loginfo;
#pid      logs/nginx.pid;

events {
worker_connections1024;
}

http {
include       mime.types;
default_typeapplication/octet-stream;
log_formatmain'$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_loglogs/access.logmain;
sendfile      on;
keepalive_timeout65;
gzipon;
server {
listen       80;
server_namelocalhost;
#charset koi8-r;
access_loglogs/host.access.logmain;
location / {
# root   html;
# indexindex.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_page404            /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)
页: [1]
查看完整版本: 构建nginx lua redis高并发应用