Skip to content

Commit

Permalink
Merge pull request #8 from flownative/7-make-cache-lifetime-for-stati…
Browse files Browse the repository at this point in the history
…c-files-configurable

Configurable lifetime for static files
  • Loading branch information
robertlemke authored May 5, 2022
2 parents 5c99174 + 5b3435e commit 682db40
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ for possible values. The default value is `warn`.
| BEACH_NGINX_CUSTOM_METRICS_SOURCE_PATH | string | /metrics | Path where metrics are located |
| BEACH_NGINX_CUSTOM_METRICS_TARGET_PORT | integer | 8082 | Port at which Nginx should listen to provide the metrics for scraping |
| BEACH_NGINX_MODE | string | Flow | Either "Flow" or "Static"; this variable is going to be renamed in the future |
| BEACH_STATIC_RESOURCES_LIFETIME | string | 30d | Expiration time for static resources; examples: "3600s" or "7d" or "max"
| FLOW_HTTP_TRUSTED_PROXIES | string | 10.0.0.0/8 | Nginx passes FLOW_HTTP_TRUSTED_PROXIES to the virtual host using the value of this variable |

## Security aspects
Expand Down
30 changes: 23 additions & 7 deletions root-files/opt/flownative/lib/nginx-legacy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,16 @@ server {
log_not_found off;
}
location = /favicon.ico {
location = /site.webmanifest {
log_not_found off;
access_log off;
expires ${NGINX_STATIC_FILES_LIFETIME};
}
location ~ ^/(android-chrome-.+|apple-touch-icon|favicon.*|mstile-.+|safari-pinned-tab).(png|svg|jpg|ico)$ {
log_not_found off;
access_log off;
expires ${NGINX_STATIC_FILES_LIFETIME};
}
EOM
Expand Down Expand Up @@ -184,7 +191,7 @@ EOM
# pass persistent resource requests to GCS
location ~* "^${BEACH_PERSISTENT_RESOURCES_BASE_PATH}([a-f0-9]{40})/" {
resolver 8.8.8.8;
expires 3600;
expires ${NGINX_STATIC_FILES_LIFETIME};
proxy_set_header Authorization "";
add_header Via 'Beach Asset Proxy';
${addHeaderStrictTransportSecurity}
Expand All @@ -193,9 +200,9 @@ EOM
EOM
elif [ -n "${BEACH_PERSISTENT_RESOURCES_FALLBACK_BASE_URI}" ]; then
cat >>"${NGINX_CONF_PATH}/sites-enabled/site.conf" <<-EOM
location ~* ^/_Resources/Persistent/(.*)$ {
location ~* "^${BEACH_PERSISTENT_RESOURCES_BASE_PATH}(.*)$ {
access_log off;
expires 3600;
expires ${NGINX_STATIC_FILES_LIFETIME};
add_header Via '\$hostname' always;
${addHeaderStrictTransportSecurity}
try_files \$uri @fallback;
Expand All @@ -209,7 +216,16 @@ EOM
proxy_pass \$assetUri;
}
EOM

else
cat >>"${NGINX_CONF_PATH}/sites-enabled/site.conf" <<-EOM
location ~* ^/_Resources/Persistent/(.*)$ {
access_log off;
expires ${NGINX_STATIC_FILES_LIFETIME};
add_header Via '\$hostname' always;
${addHeaderStrictTransportSecurity}
try_files \$uri -404;
}
EOM
fi

cat >>"${NGINX_CONF_PATH}/sites-enabled/site.conf" <<-EOM
Expand All @@ -221,9 +237,9 @@ EOM
# for all static resources
location ~ ^/_Resources/Static/ {
add_header Via '\$hostname' always;
add_header X-Static-Resource '\$hostname' always;
access_log off;
expires 3600;
expires ${NGINX_STATIC_FILES_LIFETIME};
}
}
EOM
Expand Down
2 changes: 2 additions & 0 deletions root-files/opt/flownative/lib/nginx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export NGINX_CACHE_BACKGROUND_UPDATE="${NGINX_CACHE_BACKGROUND_UPDATE:-off}"
export NGINX_CUSTOM_ERROR_PAGE_CODES="${NGINX_CUSTOM_ERROR_PAGE_CODES:-500 501 502 503}"
export NGINX_CUSTOM_ERROR_PAGE_TARGET="${NGINX_CUSTOM_ERROR_PAGE_TARGET:-}"
export NGINX_STATIC_FILES_LIFETIME=${NGINX_STATIC_FILES_LIFETIME:-30d}
export PATH="${PATH}:${NGINX_BASE_PATH}/bin"
EOF
}
Expand Down

0 comments on commit 682db40

Please sign in to comment.