From 315feac9d2d3e2caff65f06be216314d49dc6f0d Mon Sep 17 00:00:00 2001 From: Nandi Wong Date: Thu, 8 Apr 2021 00:35:04 +0800 Subject: [PATCH 1/2] test nginx reverse proxy --- .dockerignore | 4 +++- Dockerfile | 14 +++++--------- nginx/nginx.conf | 11 +++++++++++ 3 files changed, 19 insertions(+), 10 deletions(-) create mode 100644 nginx/nginx.conf diff --git a/.dockerignore b/.dockerignore index 516fde6..e1867de 100644 --- a/.dockerignore +++ b/.dockerignore @@ -4,4 +4,6 @@ Dockerfile build # prevent shipping local development html -public/index-*.html \ No newline at end of file +public/index-*.html + +.env* diff --git a/Dockerfile b/Dockerfile index 6d59e5f..b6c3291 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,16 +11,12 @@ RUN yarn install --prod COPY . . RUN NODE_ENV=production yarn build -FROM node:12-alpine -RUN apk update && apk add --no-cache bash git -RUN yarn global add serve -WORKDIR /usr/src/app +FROM nginx:1.18 + +WORKDIR /usr/share/nginx/html COPY --from=0 /usr/src/app/build . COPY --from=0 /usr/src/app/scripts/replaceEnvVars.sh . -EXPOSE 5000 -# avoid building everytime -ARG GITHUB_SHA_ARG -ENV GITHUB_SHA=$GITHUB_SHA_ARG +COPY --from=0 /usr/src/app/nginx/nginx.conf /etc/nginx/conf.d/default.conf -CMD ./replaceEnvVars.sh && serve -s . +CMD ./replaceEnvVars.sh && nginx -g 'daemon off;' diff --git a/nginx/nginx.conf b/nginx/nginx.conf new file mode 100644 index 0000000..9deff06 --- /dev/null +++ b/nginx/nginx.conf @@ -0,0 +1,11 @@ +server { + + listen 80; + + root /usr/share/nginx/html; + index index.html; + location /api { + proxy_pass http://localhost:8090; + } + +} From 4d5e95e34695d1381c13db78c955c1adad089630 Mon Sep 17 00:00:00 2001 From: Nandi Wong Date: Mon, 12 Apr 2021 00:06:49 +0800 Subject: [PATCH 2/2] add reroute for the API path --- nginx/nginx.conf | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/nginx/nginx.conf b/nginx/nginx.conf index 9deff06..d76d6f6 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -4,8 +4,15 @@ server { root /usr/share/nginx/html; index index.html; + location /api { - proxy_pass http://localhost:8090; + rewrite /api/(.*) /$1 break; + proxy_pass http://kinto-core:8090; + proxy_set_header Host $host; + } + + location /app { + try_files $uri $uri/ /index.html =404; } }