Skip to content

Commit

Permalink
feat(nginx): make worker_processes and worker_connections configu…
Browse files Browse the repository at this point in the history
…rable (#1632)
  • Loading branch information
shauke authored Apr 22, 2024
1 parent 1618b05 commit 8f6e86f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
18 changes: 17 additions & 1 deletion docs/guides/nginx-startup.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ The two NGINX modules
- `ngx_http_brotli_filter_module.so` – for compressing responses on-the-fly
- `ngx_http_brotli_static_module.so` - for serving pre-compressed files

are built in the [`Dockerfile`](../../nginx/Dockerfile) using an NGINX archive in a version which matches the openresty Docker image version and are referenced in [`nginx.conf`](../../nginx/nginx.conf).
are built in the [`Dockerfile`](../../nginx/Dockerfile) using an NGINX archive in a version which matches the openresty Docker image version and are referenced in [`nginx.conf.tmpl`](../../nginx/nginx.conf.tmpl).
The archive needs to be used because it includes the `configure` command.
The `./configure` [arguments](https://github.com/google/ngx_brotli?tab=readme-ov-file#dynamically-loaded) are taken from the current openresty configuration using `nginx -V` (`--add-module` arguments are excluded), see [ngx_brotli
](https://github.com/google/ngx_brotli?tab=readme-ov-file#dynamically-loaded).
Expand All @@ -280,6 +280,22 @@ The modules can also be built using an openresty archive, but in this case the b
- replace `make modules` with `make && make install`
- the two Brotli modules are built into the folder _/build/nginx-<version>/objs/_

## Environment Variables

NGINX environment variables need to be configured in the `cache.extraEnvVars` section of the [PWA Helm Chart](https://github.com/intershop/helm-charts/tree/main/charts/pwa), e.g.

```yaml
cache:
extraEnvVars:
- name: NGINX_WORKER_PROCESSES
value: auto
```

| parameter | format | default | comment |
| ------------------------ | ------ | ------- | -------------------------------------------------------- |
| NGINX_WORKER_PROCESSES | string | `auto` | overwrite the default `worker_processes` configuration |
| NGINX_WORKER_CONNECTIONS | string | `1024` | overwrite the default `worker_connections` configuration |

## Further References

- [Concept - Multi-Site Handling](../concepts/multi-site-handling.md)
Expand Down
2 changes: 1 addition & 1 deletion nginx/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ RUN apt-get update \
&& apt-get install --no-install-recommends --no-install-suggests -y apache2-utils libnss3-tools \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
COPY nginx.conf /etc/nginx/nginx.conf
COPY nginx.conf.tmpl /etc/nginx/nginx.conf.tmpl
COPY features /etc/nginx/features/
COPY templates /etc/nginx/templates/
COPY docker-entrypoint.d/*.sh /docker-entrypoint.d/
Expand Down
2 changes: 2 additions & 0 deletions nginx/docker-entrypoint.d/40-gomplate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@ then
fi

/gomplate -d "domains=$MULTI_CHANNEL_SOURCE" -d "overrideIdentityProviders=$OVERRIDE_IDENTITY_PROVIDERS_SOURCE" -d "cachingIgnoreParams=$CACHING_IGNORE_PARAMS_SOURCE" -d "additionalHeaders=$ADDITIONAL_HEADERS_SOURCE" -d 'ipwhitelist=env:///BASIC_AUTH_IP_WHITELIST?type=application/yaml' --input-dir="/etc/nginx/templates" --output-map='/etc/nginx/conf.d/{{ .in | strings.ReplaceAll ".conf.tmpl" ".conf" }}'

/gomplate -f /etc/nginx/nginx.conf.tmpl -o /etc/nginx/nginx.conf
4 changes: 2 additions & 2 deletions nginx/nginx.conf → nginx/nginx.conf.tmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

user nginx;
worker_processes auto;
worker_processes {{ getenv "NGINX_WORKER_PROCESSES" "auto" }};

error_log /var/log/nginx-error.log warn;
error_log /dev/stdout;
Expand All @@ -12,7 +12,7 @@ load_module /etc/nginx/modules/ngx_http_brotli_filter_module.so;
load_module /etc/nginx/modules/ngx_http_brotli_static_module.so;

events {
worker_connections 1024;
worker_connections {{ getenv "NGINX_WORKER_CONNECTIONS" "1024" }};
}

env REDIS_URI;
Expand Down

0 comments on commit 8f6e86f

Please sign in to comment.