Nginx + Lua + Cookie 控制灰度发布

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

猜你喜欢

转载自www.cnblogs.com/zero0r1/p/11996840.html