Toggle navigation
Toggle navigation
This project
Loading...
Sign in
ops
/
yoho-ansible-roles
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
chunhua.zhang
5 years ago
Commit
8cf549570c6a0877920085ff00185811bcac6069
1 parent
49e49bc7
redirect to gray
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
8 deletions
roles/openresty/files/java-nginx-config/nginx/conf/redirect.lua
roles/openresty/files/java-nginx-config/nginx/conf/vhosts/api.yoho.cn.conf
roles/openresty/templates/nginx.conf.j2
roles/openresty/files/java-nginx-config/nginx/conf/redirect.lua
View file @
8cf5495
local
http_request
=
require
"http_request"
local
switch_controller
=
require
"switch_controller"
local
iptool
=
require
"iptool"
function
do_direct
(
redirectPath
)
...
...
@@ -70,8 +71,16 @@ end
function
get_redirect_url
()
local
redirectPath
=
"/apigateway"
local
awsPath
=
"/apiaws
"
local
grayPath
=
"/apigateway2
"
---- check if gray
if
ngx
.
var
.
host
==
'api.yoho.yohoops.org'
or
ngx
.
var
.
host
==
'service.yoho.yohoops.org'
then
local
is_gray_container
=
iptool
:
pcall_check_ip_in_ipblock
(
ngx
.
var
.
remote_addr
,
"192.168.96.0/19"
,
false
)
local
is_gray_java
=
iptool
:
pcall_check_ip_in_ipblock
(
ngx
.
var
.
remote_addr
,
"10.66.71.0/19"
,
false
)
if
is_gray_container
or
is_gray_java
then
return
grayPath
end
end
-- get params
local
force_uid
=
switch_controller
.
get_force_uid
()
...
...
@@ -83,7 +92,7 @@ function get_redirect_url()
end
-- force uid
if
force_uid
and
uid
==
force_uid
then
return
aws
Path
return
gray
Path
end
--- hash percentage
...
...
@@ -91,7 +100,7 @@ function get_redirect_url()
if
percentage
>=
1
then
local
hash
=
uid
%
100
if
uid
>
0
and
hash
<=
percentage
then
return
aws
Path
return
gray
Path
end
end
return
redirectPath
...
...
roles/openresty/files/java-nginx-config/nginx/conf/vhosts/api.yoho.cn.conf
View file @
8cf5495
...
...
@@ -203,10 +203,11 @@ server {
proxy_set_header
Host
$
host
;
}
location
/
apiaws
{
## gray configuration
location
/
apigateway2
{
internal
;
proxy_redirect
off
;
proxy_pass
http
://
java
-
aws
/
gateway
;
proxy_pass
http
://
apigateway
-
gray
/
gateway
;
proxy_set_header
X
-
Real
-
IP
$
real_ip
;
proxy_set_header
X
-
Forwarded
-
For
$
proxy_add_x_forwarded_for
;
proxy_set_header
Accept
-
Encoding
"gzip"
;
...
...
roles/openresty/templates/nginx.conf.j2
View file @
8cf5495
...
...
@@ -168,9 +168,9 @@ http
#apigatewayend
# upstream for yoho-core-java aws
upstream java-aws {
server {{ groups['java-gateway'][0] }}:8080 max_fails=5 fail_timeout=3s;
# upstream for gray java gateway
upstream apigateway-gray {
server 10.66.71.6:8080 max_fails=5 fail_timeout=3s;
keepalive 32;
}
#apigatewayend
...
...
Please
register
or
login
to post a comment