diff --git a/README.md b/README.md index e2e77ca..34921bd 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,8 @@ Below is the complete list of available options that can be used to customize yo | `CACHE_PUBLIC_EXPIRATION` | `1y` | Time to set for header `Expires`. See http://nginx.org/en/docs/http/ngx_http_headers_module.html#expires | | `CHARSET` | `utf-8` | Charset being used in `Content-Type` response header field. See http://nginx.org/en/docs/http/ngx_http_charset_module.html | | `CUSTOM_SERVER_CONFIG` | ` ` | Need to add some advanced/custom nginx config? No problem, you can inject through this environment variable. **NOTE:** would be discarded if `/etc/nginx/server.conf` is present. | +| `CUSTOM_LOCATION_CACHE_IGNORE` | ` ` | Need to add some advanced/custom nginx config to the `location` for html files? No problem, you can inject through this environment variable. **NOTE:** would be discarded if `/etc/nginx/location_cache_ignore.conf` is present. | +| `CUSTOM_LOCATION_CACHE_PUBLIC` | ` ` | Need to add some advanced/custom nginx config to the `location` for cached files? No problem, you can inject through this environment variable. **NOTE:** would be discarded if `/etc/nginx/location_cache_public.conf` is present. | | `DEBUG` | `false` | If set to `true` the configuration is being printed before the server starts. | | `GZIP_LEVEL` | `6` | Gzip compression level of a response. See http://nginx.org/en/docs/http/ngx_http_gzip_module.html#gzip_comp_level | | `GZIP_TYPES` | `application/javascript application/x-javascript application/rss+xml text/javascript text/css image/svg+xml` | MIME types in addition to `text/html` for which gzip compression should be enabled. See http://nginx.org/en/docs/http/ngx_http_gzip_module.html#gzip_types | @@ -78,3 +80,9 @@ Alternatively you can use a custom Dockerfile and copy the file on build: ``` **NOTE:** By adding the file `/etc/nginx/server.conf`, all the contents of the `CUSTOM_SERVER_CONFIG` environment variable will be discarded. + +You can also mount a file to `/etc/nginx/location_cache_ignore.conf` or `/etc/nginx/location_cache_public.conf` to add custom nginx configuration to our defined locations. For example this can be useful to add headers to avoid robots to crawl the content in a staging environemnt: + +``` +add_header x-robots-tag "noindex, follow" always; +``` \ No newline at end of file diff --git a/nginx-boot.sh b/nginx-boot.sh index 9e568bd..8a20b4a 100755 --- a/nginx-boot.sh +++ b/nginx-boot.sh @@ -41,6 +41,18 @@ else CUSTOM_SERVER_CONFIG=${CUSTOM_SERVER_CONFIG:-}; fi +if [ -f /etc/nginx/location_cache_ignore.conf ]; then + CUSTOM_LOCATION_CACHE_IGNORE=$( $NGINX_CONF daemon off; @@ -92,10 +104,12 @@ http { error_page 404 /404.html; location ~* \.($CACHE_IGNORE)$ { + $CUSTOM_LOCATION_CACHE_IGNORE add_header Cache-Control "no-store"; expires off; } location ~* \.($CACHE_PUBLIC)$ { + $CUSTOM_LOCATION_CACHE_PUBLIC add_header Cache-Control "public"; expires +$CACHE_PUBLIC_EXPIRATION; }