@@ -81,6 +81,10 @@ echo "Addressing Style: ${S3_STYLE}"
8181echo " AWS Signatures Version: v${AWS_SIGS_VERSION} "
8282echo " DNS Resolvers: ${DNS_RESOLVERS} "
8383echo " Directory Listing Enabled: ${ALLOW_DIRECTORY_LIST} "
84+ echo " Proxy Caching Time for Valid Response: ${PROXY_CACHE_VALID_OK} "
85+ echo " Proxy Caching Time for Not Found Response: ${PROXY_CACHE_VALID_NOTFOUND} "
86+ echo " Proxy Caching Time for Forbidden Response: ${PROXY_CACHE_VALID_FORBIDDEN} "
87+ echo " CORS Enabled: ${CORS_ENABLED} "
8488
8589set -o nounset # abort on unbound variable
8690
123127
124128echo " ▶ Adding environment variables to NGINX configuration file: /etc/nginx/environment"
125129cat > " /etc/nginx/environment" << EOF
126- # Enables or disables directory listing for the S3 Gateway (1 =enabled, 0 =disabled)
130+ # Enables or disables directory listing for the S3 Gateway (true =enabled, false =disabled)
127131ALLOW_DIRECTORY_LIST=${ALLOW_DIRECTORY_LIST}
128132# AWS Authentication signature version (2=v2 authentication, 4=v4 authentication)
129133AWS_SIGS_VERSION=${AWS_SIGS_VERSION}
@@ -141,8 +145,35 @@ S3_SERVER=${S3_SERVER}
141145S3_STYLE=${S3_STYLE}
142146# Flag (true/false) enabling AWS signatures debug output (default: false)
143147S3_DEBUG=${S3_DEBUG}
148+ # Proxy caching time for response code 200 and 302
149+ PROXY_CACHE_VALID_OK=${PROXY_CACHE_VALID_OK}
150+ # Proxy caching time for response code 404
151+ PROXY_CACHE_VALID_NOTFOUND=${PROXY_CACHE_VALID_NOTFOUND}
152+ # Proxy caching time for response code 403
153+ PROXY_CACHE_VALID_FORBIDDEN=${PROXY_CACHE_VALID_FORBIDDEN}
154+ # Enables or disables CORS for the S3 Gateway (true=enabled, false=disabled)
155+ CORS_ENABLED=${CORS_ENABLED}
144156EOF
145157
158+ # By enabling CORS, we also need to enable the OPTIONS method which
159+ # is not normally used as part of the gateway. The following variable
160+ # defines the set of acceptable headers.
161+ if [ " ${CORS_ENABLED} " == " 1" ]; then
162+ cat >> " /etc/nginx/environment" << EOF
163+ LIMIT_METHODS_TO="GET HEAD OPTIONS"
164+ LIMIT_METHODS_TO_CSV="GET, HEAD, OPTIONS"
165+ EOF
166+ else
167+ cat >> " /etc/nginx/environment" << EOF
168+ LIMIT_METHODS_TO="GET HEAD"
169+ LIMIT_METHODS_TO_CSV="GET, HEAD"
170+ EOF
171+ fi
172+
173+ if [ -z " ${CORS_ALLOWED_ORIGIN+x} " ]; then
174+ CORS_ALLOWED_ORIGIN=" *"
175+ fi
176+
146177# Only include these env vars if we are not using a instance profile credential
147178# to obtain S3 permissions.
148179if [ $uses_iam_creds -eq 0 ]; then
@@ -305,6 +336,11 @@ download "common/etc/nginx/templates/gateway/v2_headers.conf.template" "/etc/ngi
305336download " common/etc/nginx/templates/gateway/v2_js_vars.conf.template" " /etc/nginx/templates/gateway/v2_js_vars.conf.template"
306337download " common/etc/nginx/templates/gateway/v4_headers.conf.template" " /etc/nginx/templates/gateway/v4_headers.conf.template"
307338download " common/etc/nginx/templates/gateway/v4_js_vars.conf.template" " /etc/nginx/templates/gateway/v4_js_vars.conf.template"
339+ download " common/etc/nginx/templates/gateway/cors.conf.template" " /etc/nginx/templates/gateway/cors.conf.template"
340+ download " common/etc/nginx/templates/gateway/js_fetch_trusted_certificate.conf.template" " /etc/nginx/templates/gateway/js_fetch_trusted_certificate.conf.template"
341+ download " common/etc/nginx/templates/gateway/s3listing_location.conf.template" " /etc/nginx/templates/gateway/s3listing_location.conf.template"
342+ download " common/etc/nginx/templates/gateway/s3_location.conf.template" " /etc/nginx/templates/gateway/s3_location.conf.template"
343+ download " common/etc/nginx/templates/gateway/s3_server.conf.template" " /etc/nginx/templates/gateway/s3_server.conf.template"
308344download " oss/etc/nginx/templates/upstreams.conf.template" " /etc/nginx/templates/upstreams.conf.template"
309345download " oss/etc/nginx/conf.d/gateway/server_variables.conf" " /etc/nginx/conf.d/gateway/server_variables.conf"
310346
0 commit comments