fix(nginx): 优先 127.0.0.11 与延长 DNS valid,缓解 api/web 间歇无法解析致 502

Made-with: Cursor
This commit is contained in:
whm
2026-03-23 16:53:36 +08:00
parent 5da4941913
commit 0a1fe41314
2 changed files with 8 additions and 1 deletions

View File

@@ -8,7 +8,8 @@ server {
server_name yuheng.yuxindazhineng.com; server_name yuheng.yuxindazhineng.com;
client_max_body_size 800m; client_max_body_size 800m;
resolver @@NGINX_RESOLVER@@ valid=10s ipv6=off; # valid 宿 DNS compose 502 entrypoint 127.0.0.11
resolver @@NGINX_RESOLVER@@ valid=300s ipv6=off;
ssl_certificate /etc/ssl/yh_web/yuheng.yuxindazhineng.com/fullchain.pem; ssl_certificate /etc/ssl/yh_web/yuheng.yuxindazhineng.com/fullchain.pem;
ssl_certificate_key /etc/ssl/yh_web/yuheng.yuxindazhineng.com/privkey.pem; ssl_certificate_key /etc/ssl/yh_web/yuheng.yuxindazhineng.com/privkey.pem;

View File

@@ -104,6 +104,12 @@ else
echo "yh_nginx: resolver from resolv.conf: ${NSLINE}" >&2 echo "yh_nginx: resolver from resolv.conf: ${NSLINE}" >&2
fi fi
# Docker compose 服务名由网桥内置 DNS通常 127.0.0.11)解析;仅用宿主机 DNS 会间歇「could not be resolved」→502
case "$NSLINE" in
*127.0.0.11*) ;;
*) NSLINE="127.0.0.11 ${NSLINE}"; echo "yh_nginx: prepended 127.0.0.11 for compose DNS: ${NSLINE}" >&2 ;;
esac
if [ ! -r /yuheng.docker.conf.tpl ]; then if [ ! -r /yuheng.docker.conf.tpl ]; then
echo "yh_nginx: error: /yuheng.docker.conf.tpl not mounted" >&2 echo "yh_nginx: error: /yuheng.docker.conf.tpl not mounted" >&2
exit 1 exit 1