Commit ffcfe1dd authored by tywldx's avatar tywldx

fix

parent d4fd4308
......@@ -3,9 +3,9 @@ local register_uri = args['registerFrom']
local merchant_uri = args['merchantId']
if (register_uri) then
ngx.header['Set-Cookie'] = {'registerFrom=' .. register_uri .. '; path=/;'}
ngx.header['Set-Cookie'] = {'registerFrom=' .. register_uri .. '; path=/; domain=.q-gp.com;'}
end
if (merchant_uri) then
ngx.header['Set-Cookie'] = {'merchantId=' .. merchant_uri .. '; path=/;'}
ngx.header['Set-Cookie'] = {'merchantId=' .. merchant_uri .. '; path=/; domain=.q-gp.com;'}
end
\ No newline at end of file
worker_processes 1;
error_log logs/error.log;
events {
worker_connections 1024;
}
http {
access_log logs/access.log combined;
server {
listen 8100;
server_name sc.domain.com;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml application/javascript;
gzip_vary on;
# 正常发布路径 和 灰度发布路径
set $rootPath "/Users/xuezhijie/playground/nginx/test1/public";
set $gatedRootPath "/Users/xuezhijie/playground/nginx/test1-gated/public";
# jenkins灰度渠道参数
set $gatedStr "registerFrom=1,2&merchantId=2,3";
# 解析灰度配置
# 1,2
set_by_lua_file $regConfig confs/parseConfig.lua $gatedStr "registerFrom";
# 2,3
set_by_lua_file $merchantConfig confs/parseConfig.lua $gatedStr "merchantId";
location / {
echo "http_cookie: $http_cookie";
# 获取cookie渠道号,判断是否属于灰度范围
echo "registerFrom渠道号: $cookie_registerFrom";
echo "merchantId渠道号: $cookie_merchantId";
echo "灰度配置registerFrom: $regConfig";
echo "灰度配置merchantId: $merchantConfig";
set_by_lua_file $isGray confs/isGray.lua $regConfig $merchantConfig $cookie_registerFrom $cookie_merchantId;
echo $isGray;
# 按渠道发布
if ($isGray != '') {
set $rootPath $gatedRootPath;
}
root $rootPath;
try_files $uri $uri/ /index.html;
}
}
}
\ No newline at end of file
--[[ 参数:
registerFrom 灰度设置
merchantId 灰度设置
cookie registerFrom值
cookie merchantId值
]]
local regConfig = ngx.arg[1];
local merConfig = ngx.arg[2];
local regCookie = ngx.arg[3];
local merCookie = ngx.arg[4];
local isGrayReg = false;
local isGrayMer = false;
if (regConfig ~= '' and regCookie~= '' and string.find(regConfig, regCookie)) then
isGrayReg = true;
end
if (merConfig ~= '' and merCookie ~= '' and string.find(merConfig, merCookie)) then
isGrayMer = true;
end
local isGray = '';
if (isGrayReg or isGrayMer) then
isGray = '1';
end
--print(isGray)
return isGray;
\ No newline at end of file
local t = "";
local str = ngx.arg[1];
local prop = ngx.arg[2];
-- local str = "registerFrom=1,2,3&merchantId=2,3";
-- local prop = "merchantId";
for k,v in string.gmatch(str, "(%w+)=([%w,]+)") do
if (k == prop) then
-- print(k, v)
t = v;
break;
end
end
return t;
\ No newline at end of file
......@@ -16,23 +16,23 @@ end
local path = ngx.var.normalPath;
local channelPath = ngx.var.channelPath;
-- 解析手机号和特殊渠道
local tailNumbers = string.split(ngx.var.tailNumber);
local excludeChannel = string.split(ngx.var.excludeChannel)
-- 解析渠道设置
local register = string.split(ngx.var.registerChannel);
local merchant = string.split(ngx.var.merchantChannel);
-- cookie值
local register_cookie = ngx.var.cookie_registerFrom
local merchant_cookie = ngx.var.cookie_merchantId
-- uri参数值
local args = ngx.req.get_uri_args()
local register_uri = args['registerFrom']
local merchant_uri = args['merchantId']
local phoneNo = args['phoneNo']
if (not phoneNo or string.len(phoneNo) == 0) then
phoneNo = ngx.var.cookie_phoneNo
end
local baiTiao = '222';
......@@ -46,21 +46,20 @@ if (isBatitiao) then
return channelPath;
end
-- 没有设置渠道,设置了手机号,属于特殊渠道(不属于特殊,但符合尾号规则)时,返回旧版
if (ngx.var.excludeChannel ~= '' or ngx.var.tailNumber ~= '') then
local hitExclude = isInTable(register_uri, excludeChannel) or isInTable(register_cookie, excludeChannel)
or isInTable(merchant_cookie, excludeChannel) or isInTable(merchant_uri, excludeChannel)
if (hitExclude) then
return path;
end
-- 是否符合手机尾号规则
local hitTailNumber = false
if ngx.var.cookie_phoneNo then
if phoneNo then
for key,value in ipairs(tailNumbers)
do
if (string.match(ngx.var.cookie_phoneNo, value..'$')) then
if (string.match(phoneNo, value..'$')) then
hitTailNumber = true
break
end
......@@ -72,4 +71,5 @@ if (ngx.var.excludeChannel ~= '' or ngx.var.tailNumber ~= '') then
end
end
return path;
return channelPath;
......@@ -16,7 +16,7 @@ server {
set $merchantChannel "";
set $excludeChannel "222,504,900";
set $tailNumber "0,1,2,3,4,5,6,7,8,9";
set $tailNumber "1,2,3,4,5,6,7,8,9";
location / {
expires -1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment