Skip to content

Commit

Permalink
feat: new NGINX_RESOLVERS, NGINX_RESOLVER_VALID env config (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
alimd authored Feb 26, 2025
2 parents b4350b5 + 2651c28 commit e2cd028
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
4 changes: 3 additions & 1 deletion nginx-core/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ ENV NGINX_ACCESS_LOG="/var/log/nginx/access.log json" \
NGINX_CORS_ORIGIN="*" \
NGINX_CORS_METHODS="GET, OPTIONS" \
NGINX_CORS_HEADERS="*" \
NGINX_CORS_MAXAGE=86400
NGINX_CORS_MAXAGE=86400 \
NGINX_RESOLVERS="127.0.0.11" \
NGINX_RESOLVER_VALID=10s

ENV NGINX_CLIENT_MAX_BODY_SIZE=10m \
NGINX_SENDFILE=on \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ tcp_nopush $NGINX_TCP_NOPUSH;
tcp_nodelay $NGINX_TCP_NODELAY;

# fix dns for docker and ssl
resolver 127.0.0.11 ipv6=off valid=10s;
resolver $NGINX_RESOLVERS ipv6=off valid=$NGINX_RESOLVER_VALID;
resolver_timeout 5s;
#resolver 1.1.1.1 8.8.8.8 8.8.4.4 valid=60s;
#resolver_timeout 15s;
Expand Down
18 changes: 18 additions & 0 deletions nginx/etc/nginx/entrypoint.d/10-local-resolvers.envsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh

# if $NGINX_RESOLVERS set to local, set it to the local resolvers from /etc/resolv.conf and export it

set -eu

LC_ALL=C
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

# if $NGINX_RESOLVERS is not set to local, do nothing
[ "${NGINX_RESOLVERS}" == local ] || return 0

NGINX_RESOLVERS=$(awk 'BEGIN{ORS=" "} $1=="nameserver" {if ($2 ~ ":") {print "["$2"]"} else {print $2}}' /etc/resolv.conf)

# remove trailing space
NGINX_RESOLVERS="${NGINX_RESOLVERS% }"

export NGINX_RESOLVERS

0 comments on commit e2cd028

Please sign in to comment.