Skip to content

Commit b4aa4fd

Browse files
fix: nginx DNS resolver for Railway private networking
127.0.0.11 (Docker embedded DNS) is not available in Railway's container environment. Instead, the correct nameserver is in /etc/resolv.conf at runtime. Changes: - web/start.sh: startup script that reads nameserver from /etc/resolv.conf and substitutes __DNS_RESOLVER__ placeholder in nginx.conf before starting nginx. Falls back to 8.8.8.8 if resolv.conf is empty (shouldn't happen). - web/nginx.conf: replaces hard-coded '127.0.0.11' with '__DNS_RESOLVER__' placeholder that start.sh replaces at container startup. - web/Dockerfile: copies start.sh and uses it as the container CMD instead of launching nginx directly. This restores the /api/ and /auth/ proxy routes to api.railway.internal:3001 which allows the dashboard and Resend webhooks to work via openmail.win. Co-authored-by: ShadowWalker2014 <ShadowWalker2014@users.noreply.github.com>
1 parent f93e5db commit b4aa4fd

3 files changed

Lines changed: 25 additions & 4 deletions

File tree

web/Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,8 @@ COPY --from=builder /app/docs/dist /usr/share/nginx/html/docs
5555
# and nginx's own $uri / $uri/ variables are preserved correctly.
5656
COPY web/nginx.conf /etc/nginx/conf.d/default.conf
5757

58+
COPY web/start.sh /start.sh
59+
RUN chmod +x /start.sh
60+
5861
EXPOSE 80
59-
CMD ["nginx", "-g", "daemon off;"]
62+
CMD ["/start.sh"]

web/nginx.conf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ server {
44
root /usr/share/nginx/html;
55
index index.html;
66

7-
# Use Docker's internal DNS resolver so nginx re-resolves Railway
8-
# private hostnames (api.railway.internal) instead of caching them.
9-
resolver 127.0.0.11 valid=30s ipv6=off;
7+
# DNS resolver is injected at startup from /etc/resolv.conf by start.sh.
8+
# Placeholder is replaced with the container's actual nameserver IP.
9+
resolver __DNS_RESOLVER__ valid=30s ipv6=off;
1010

1111
# Security headers
1212
add_header X-Frame-Options "SAMEORIGIN" always;

web/start.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/sh
2+
# Resolve the container's actual DNS nameserver at startup and inject it
3+
# into nginx.conf so nginx can re-resolve Railway private hostnames
4+
# (api.railway.internal) without caching stale IPs across service restarts.
5+
#
6+
# Railway containers use a non-Docker DNS (not 127.0.0.11) — the correct
7+
# nameserver is in /etc/resolv.conf at runtime.
8+
9+
NS=$(grep -m1 nameserver /etc/resolv.conf | awk '{print $2}')
10+
if [ -z "$NS" ]; then
11+
echo "WARN: Could not read nameserver from /etc/resolv.conf, defaulting to 8.8.8.8"
12+
NS="8.8.8.8"
13+
fi
14+
15+
echo "INFO: Using DNS resolver: $NS"
16+
sed -i "s|__DNS_RESOLVER__|$NS|g" /etc/nginx/conf.d/default.conf
17+
18+
exec nginx -g "daemon off;"

0 commit comments

Comments
 (0)