Skip to content

Commit

Permalink
fix(gateway): fix fs-proxy nginx conf #35
Browse files Browse the repository at this point in the history
  • Loading branch information
maslow committed Jan 20, 2022
1 parent d5a4deb commit 21efaab
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/gateway/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ RUN apt-get update && apt-get install -y wget
WORKDIR /app
EXPOSE 80

ENV SERVICE_DRIVER docker
ENV SERVICE_DRIVER=docker

ADD ./conf.docker /conf.docker
ADD ./conf.kubernetes /conf.kubernetes
Expand Down
15 changes: 12 additions & 3 deletions packages/gateway/conf.docker/fs-proxy.conf
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,18 @@ server {
# resolve fs service
resolver 127.0.0.11;

# Quirks:
# 1. since $uri is the decoded the uri, we want original uri to support non-ASCII characters,
# 2. and nginx will re-encode the $uri string in regexp
# 3. so welcome $fixed_uri
if ($uri ~* "(.*)$") {
set $fixed_uri $1;
}

# resolve proxy uri
if ($host ~* "(\w{8}(-\w{4}){3}-\w{12}_[\w|\d]{1,32})\.(.+)$") {
set $bucket $1;
set $proxy_uri $bucket?path=$uri&$query_string;
set $proxy_uri $bucket?path=$fixed_uri&$query_string;
}

if ($uri ~* "/dir$") {
Expand All @@ -55,14 +63,15 @@ server {

# proxy
proxy_pass http://storage-service:9010/$proxy_uri;
proxy_read_timeout 600s;
add_header bucket $bucket;
add_header appid $appid;
proxy_read_timeout 600s;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

# Logging
log_by_lua_block {
ngx.log(ngx.ERR, '<proxy domain>', ngx.var.userdomain, ngx.var.uri);
ngx.log(ngx.ERR, '<$proxy_uri> ', ngx.var.proxy_uri, ' <$fixed_uri> ', ngx.var.fixed_uri);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/gateway/conf.kubernetes/app.conf
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ server {
set $proxy_uri $bucket/dir$is_args$query_string;
}

proxy_pass http://storage-service:9010/$proxy_uri;
proxy_pass http://storage-service.laf.svc.cluster.local:9010/$proxy_uri;
add_header appid $appid;
add_header bucket $bucket;
proxy_read_timeout 600s;
Expand Down
15 changes: 12 additions & 3 deletions packages/gateway/conf.kubernetes/fs-proxy.conf
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,18 @@ server {
return 204;
}

# Quirks:
# 1. since $uri is the decoded the uri, we want original uri to support non-ASCII characters,
# 2. and nginx will re-encode the $uri string in regexp
# 3. so welcome $fixed_uri
if ($uri ~* "(.*)$") {
set $fixed_uri $1;
}

# resolve proxy uri
if ($host ~* "(\w{8}(-\w{4}){3}-\w{12}_[\w|\d]{1,32})\.(.+)$") {
set $bucket $1;
set $proxy_uri $bucket?path=$uri&$query_string;
set $proxy_uri $bucket?path=$fixed_uri&$query_string;
}

if ($uri ~* "/dir$") {
Expand All @@ -54,14 +62,15 @@ server {

# proxy
proxy_pass http://storage-service.laf.svc.cluster.local:9010/$proxy_uri;
proxy_read_timeout 600s;
add_header appid $appid;
add_header bucket $bucket;
proxy_read_timeout 600s;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

# Logging
log_by_lua_block {
ngx.log(ngx.ERR, '<proxy domain>', ngx.var.proxy_uri, ngx.var.uri);
ngx.log(ngx.ERR, '<$proxy_uri> ', ngx.var.proxy_uri, ' <$fixed_uri> ', ngx.var.fixed_uri);
}
}
}
Expand Down

0 comments on commit 21efaab

Please sign in to comment.