From 9707928313df2691c92294de32b1facf7ec114de Mon Sep 17 00:00:00 2001 From: Fernando Sanchez Date: Wed, 20 Jul 2022 13:22:48 -0300 Subject: [PATCH 1/7] Plausible --- frontend/Dockerfile.stage | 2 ++ frontend/deploy/app.conf | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 frontend/deploy/app.conf diff --git a/frontend/Dockerfile.stage b/frontend/Dockerfile.stage index 09a2bf089..89dc821eb 100644 --- a/frontend/Dockerfile.stage +++ b/frontend/Dockerfile.stage @@ -21,8 +21,10 @@ RUN yarn build # DEPLOY CLIENT FROM nginx:latest as production-stage +RUN mkdir -p /var/run/nginx-cache && chmod 0755 /var/run/nginx-cache WORKDIR /app COPY --from=build-stage /app/packages/client/build /app COPY ./deploy/nginx.conf /etc/nginx/nginx.conf +COPY ./deploy/app.conf /etc/nginx/conf.d/app.conf EXPOSE 80 RUN ls -la /app \ No newline at end of file diff --git a/frontend/deploy/app.conf b/frontend/deploy/app.conf new file mode 100644 index 000000000..abf285160 --- /dev/null +++ b/frontend/deploy/app.conf @@ -0,0 +1,35 @@ +# Only needed if you cache the plausible script. Speeds things up. +# Note: to use the `proxy_cache` setup, you'll need to make sure the `/var/run/nginx-cache` +# directory exists (e.g. creating it in a build step with `mkdir -p /var/run/nginx-cache`) +# To make `/var/run/nginx-cache` persist during reboots of your server +# make sure to run `echo "D /run/nginx-cache 0755 root root -" > /usr/lib/tmpfiles.d/nginx-cache.conf` +proxy_cache_path /var/run/nginx-cache/jscache levels=1:2 keys_zone=jscache:100m inactive=30d use_temp_path=off max_size=100m; + +server { + ... + location = /js/script.js { + # Change this if you use a different variant of the script + proxy_pass https://plausible.io/js/script.js; + + # Tiny, negligible performance improvement. Very optional. + proxy_buffering on; + + # Cache the script for 6 hours, as long as plausible.io returns a valid response + proxy_cache jscache; + proxy_cache_valid 200 6h; + proxy_cache_use_stale updating error timeout invalid_header http_500; + + # Optional. Adds a header to tell if you got a cache hit or miss + add_header X-Cache $upstream_cache_status; + } + + location = /api/event { + proxy_pass https://plausible.io/api/event; + proxy_buffering on; + proxy_http_version 1.1; + + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-Host $host; + } +} \ No newline at end of file From 7cf6ae2d910a17bbd2d26fde6a94b9fcc9b2e0dc Mon Sep 17 00:00:00 2001 From: German Urrustarazu Date: Wed, 20 Jul 2022 14:11:35 -0300 Subject: [PATCH 2/7] update index --- frontend/packages/client/public/index.html | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/frontend/packages/client/public/index.html b/frontend/packages/client/public/index.html index ab9019663..9bbb8a9b2 100644 --- a/frontend/packages/client/public/index.html +++ b/frontend/packages/client/public/index.html @@ -28,8 +28,9 @@ CAST