解决DNS导致nginx反代失败

VPS默认DNS失效导致Nginx反代失败,提示upstream xxxx且主机此时无法ping通其他域名,此时需指定DNS服务器。

由于Debian的/etc/resolv.conf默认是软链接,需要删除重建,否则重启会失效。

1
2
3
4
5
sudo cp /etc/resolv.conf  /etc/resolv.conf1

sudo rm /etc/resolv.conf

sudo mv /etc/resolv.conf1 /etc/resolv.conf

重建好之后,再次确认文件权限配置,否则按以下情况处理

1
2
sudo chown root:root /etc/resolv.conf
sudo chmod 644 /etc/resolv.conf

修改/etc/resov.conf文件内容,例如

1
2
3
4
5
6
7
8
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 119.29.29.29
nameserver 180.76.76.76
nameserver 101.6.6.6
nameserver 240c::6666
nameserver 240c::6644
nameserver 2001:da8::666

为确保万无一失,可以检查/etc/network/interfaces中的DNS服务器配置是否正确,例如

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug eth0
iface eth0 inet static
address 11.111.111.111
netmask 255.255.254.0
network 11.11.111.0
broadcast 11.111.111.255
gateway 11.111.111.1
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 119.29.29.29 180.76.76.76 101.6.6.6 77.88.8.8 1.1.1.1 8.8.8.8
dns-search kvm.233
iface eth0 inet6 static
address 2400:c700:1::6:ef
netmask 64
gateway 2400:c700:1::1
dns-nameservers 2001:da8::666 2001:4860:4860::8844 2001:4860:4860::8888 209.244.0.3 2a00:b700::220 2a00:b700:1::220


解决DNS导致nginx反代失败
https://hexo.psorai.eu.org/2023/06/27/解决DNS导致Nginx反代失败/
Author
Sora
Posted on
June 27, 2023
Licensed under