Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom configuration for both location #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -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;
```
14 changes: 14 additions & 0 deletions nginx-boot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=$(</etc/nginx/location_cache_ignore.conf)
else
CUSTOM_LOCATION_CACHE_IGNORE=${CUSTOM_LOCATION_CACHE_IGNORE:-};
fi

if [ -f /etc/nginx/location_cache_public.conf ]; then
CUSTOM_LOCATION_CACHE_PUBLIC=$(</etc/nginx/location_cache_public.conf)
else
CUSTOM_LOCATION_CACHE_PUBLIC=${CUSTOM_LOCATION_CACHE_PUBLIC:-};
fi

# Build config
cat <<EOF > $NGINX_CONF
daemon off;
Expand Down Expand Up @@ -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;
}
Expand Down