Skip to content

Commit

Permalink
add NAMESERVER environment variable for nginx dns resolver (#124)
Browse files Browse the repository at this point in the history
* ✨ nginx dns resolver is now configurable.

* 📝 add Optional Environment Variables section in README.md
  • Loading branch information
knaoe authored Nov 17, 2023
1 parent eec5958 commit 8f85bb8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ volumes:
kratos-sqlite:
```

### Optional Environment Variables
- `NAMESERVER`: the nameserver to use for dns resolution for kratos urls. By default, it reads values from /etc/resolv.conf, so it works well without setting this value in many runtimes. If there is no /etc/resolv.conf, it will be set to `127.0.0.11` (Docker dns).

## Start local

It is required, that a local instance of ory kratos is running. the latest tested version is `v1.0.0`.
Expand Down
6 changes: 2 additions & 4 deletions kratos-admin-ui/deploy/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ server {
listen 80;

location /api/admin/ {
# see https://www.emmanuelgautier.com/blog/nginx-docker-dns-resolution
resolver 127.0.0.11;
resolver $NAMESERVER valid=30s;

rewrite /api/admin/(.*) /admin/$1 break;

Expand All @@ -33,8 +32,7 @@ server {
}

location /api/public/ {
# https://www.emmanuelgautier.com/blog/nginx-docker-dns-resolution
resolver 127.0.0.11;
resolver $NAMESERVER valid=30s;

rewrite /api/public/(.*) /$1 break;

Expand Down
11 changes: 11 additions & 0 deletions kratos-admin-ui/deploy/start.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
if [ -z ${NAMESERVER+x} ]; then
if [ -f /etc/resolv.conf ]; then
export NAMESERVER=$(awk '/^nameserver/{print $2}' /etc/resolv.conf)
else
# see https://www.emmanuelgautier.com/blog/nginx-docker-dns-resolution
export NAMESERVER="127.0.0.11"
fi
fi

echo "Nameserver is: $NAMESERVER"

checkFormat() {
regex="http?(s)://"
if [ "$1" == $regex* ]; then
Expand Down

0 comments on commit 8f85bb8

Please sign in to comment.