openresty 學習筆記六:使用session庫
lua-resty-session 是一個面向 OpenResty 的安全和靈活的 session 庫,它實現了 Secure Cookie Protocol。
項目地址:https://github.com/bungle/lua-resty-session
使用方法有很多種,我這里只使用簡單的用redis存儲session
先要修改redis配置文件vim /usr/local/redis/etc/redis.conf
,開啟unix socket
unixsocket /tmp/redis.sock
unixsocketperm 777
並在nginx.conf
上添加配置
server
{
set $session_storage redis;
set $session_redis_prefix sessions;
set $session_redis_socket unix:///tmp/redis.sock;
set $session_redis_host 127.0.0.1;
set $session_redis_port 6379;
}
使用方法
local session = require "resty.session".open()
session.data.xxx = abc
session:save()