From 5f35420f786c664ca49751d7e8ced8e08080f025 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Goc=C5=82awski?= Date: Tue, 23 Jan 2018 15:54:38 +0100 Subject: [PATCH] Add NOT_FOUND_MEANS_INDEX option. --- README.md | 1 + nginx-gcs-proxy/Dockerfile | 1 + nginx-gcs-proxy/nginx.conf.tmpl | 3 +++ 3 files changed, 5 insertions(+) diff --git a/README.md b/README.md index ee097f6..d73b558 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ Variable | Description | Default --- | --- | --- `GCS_BUCKET_URL` | Full URL to the bucket folder. `https://storage.googleapis.com/[GCS_BUCKET_URL]/index.html` | None - required! `LISTEN_PORT` | Server listen port | 8080 +`NOT_FOUND_MEANS_INDEX` | When requested path is not found in the bucket, return index.html. Useful when serving single page apps, like Angular, React, Ember. Possible values: "true", "false". | false ## Health-checking diff --git a/nginx-gcs-proxy/Dockerfile b/nginx-gcs-proxy/Dockerfile index 7998ca5..f27bf60 100644 --- a/nginx-gcs-proxy/Dockerfile +++ b/nginx-gcs-proxy/Dockerfile @@ -11,6 +11,7 @@ COPY nginx.conf.tmpl /etc/nginx/nginx.conf.tmpl ENV GCS_BUCKET_URL " " ENV LISTEN_PORT "8080" +ENV NOT_FOUND_MEANS_INDEX "false" ENTRYPOINT ["dockerize", \ "-template", \ diff --git a/nginx-gcs-proxy/nginx.conf.tmpl b/nginx-gcs-proxy/nginx.conf.tmpl index c7846c5..b9b2a8b 100644 --- a/nginx-gcs-proxy/nginx.conf.tmpl +++ b/nginx-gcs-proxy/nginx.conf.tmpl @@ -90,6 +90,9 @@ http { proxy_cache_valid 200 1d; add_header X-Cache $upstream_cache_status; + {{ if eq .Env.NOT_FOUND_MEANS_INDEX "true" }} + error_page 404 =200 /index.html; + {{ end }} proxy_pass http://google-cloud-storage/{{ .Env.GCS_BUCKET_URL }}$uri; } }