Nginx + Lua + Cookie 控制灰度發布
一、下載安裝
1、 安裝 OpenResty下載頁、 openresty-1.15.8.2.tar.gz包(點擊下載)、包版本列表
2、 安裝指導頁(點擊打開)
3、 參考CentOS
二、 命令安裝
1、 - brew
- $ brew install openresty/brew/openresty
2、 查看openResty 安裝目錄
- $ nginx -t
如圖:
3、 設置別名
- $ export PATH=/usr/local/opt/openresty/nginx/sbin:$PATH
4、 啟動
- $ nginx
三、 設置工作目錄如:配置文件 conf 如:nginx.conf
1、 通過 nginx -t
2、 拷貝 配置文件夾到 工作目錄
- $ cp -r /usr/local/etc/nginx ~/work
修改nginx 文件夾為 conf 名
- $ mv nginx conf
如圖:
四、 修改nginx.conf 引入Lua腳本
如圖:
五、 設置resty.cookie
1、拷貝代碼https://github.com/cloudflare/lua-resty-cookie/blob/master/lib/resty/cookie.lua
2、打開
查看安裝目錄,將cookie.lua 寫入lualib/resty目錄中
$ which nginx
$ open /usr/local/opt/openresty/lualib/resty
$ touch cookie.lua
$ vim cookie.lua { github code}

以下是Lua 腳本可用參考
如圖:
代碼文件:
https://docs.qq.com/doc/DZmJkaGpNd094RWpM
常用命令:
查看nginx 安裝目錄
which nginx
Alias:
export PATH=/usr/local/opt/openresty/nginx/sbin:$PATH
查看配置文件
nginx -t
啟動:
Nginx
nginx -p `pwd` -c ~/work/conf/nginx.conf
-p 指定“當前工作”目錄
-c 指定配置文件目錄
重載:
nginx -s reload
