尝试连接到本地主机时鱿鱼 DNS 失败
Squid DNS FAIL when trying to connect to localhost
我是 运行 本地 http 服务器和本地 squid 实例。本地 http 客户端打开一个连接到 squid 实例的套接字,这似乎可以正常工作。然后,我尝试通过发出以下 http 请求来连接到本地 http 服务器:
CONNECT localhost:80 HTTP/1.1\r\n
产生响应 headers
Content-Language en
Content-Length 3612
Content-Type text/html;charset=utf-8
Date Thu, 21 Jun 2018 17:28:10 GMT
Mime-Version 1.0
Server squid/3.5.27
Vary Accept-Language
X-Squid-Error ERR_DNS_FAIL 0
状态为 503。
我还尝试连接到 127.0.0.1,它产生了这个响应:
Content-Language en
Content-Length 3433
Content-Type text/html;charset=utf-8
Date Thu, 21 Jun 2018 17:35:16 GMT
Mime-Version 1.0
Server squid/3.5.27
Vary Accept-Language
X-Squid-Error ERR_CONNECT_FAIL 111
我的 squid.conf 看起来像这样:
http_port 3128
coredump_dir /var/spool/squid
acl SSL_ports port 443
acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 443 # https
acl Safe_ports port 1025-65535 # unregistered ports
acl CONNECT method CONNECT
acl any_host src all
acl all_dst dst all
http_access allow any_host
http_access allow all_dst
是否有不同的方式告诉 squid 连接到本地主机?
squid 试图以某种方式将 localhost
解析为 127.0.0.1
,但最终导致连接失败。但是,指定 [::1]
而不是 localhost
会按预期执行。
我发现 localhost
解析为 [::1]
而不是 127.0.0.1
的失败原因。
为了绕过 /etc/hosts/
只需将以下内容添加到 /etc/squid/hosts
:
127.0.0.1 localhost
然后 hosts_file /etc/squid/hosts
在你的 squid.conf
.
当然文件可以放在任何地方。
在我的例子中,我使用的是 squid 机器主机名(例如 mysquid.proxy),问题与 DNS 解析无关,因为 squid 机器可以自行解析正确使用其主机名。
问题是由同一代理中的额外端口配置引起的。我使用 squid 作为具有两个不同端口的正向代理和反向代理:
- 3128 - 正向代理
- 443 - 反向代理
客户端正在连接到(转发)代理 mysquid.proxy:3128 并且请求类似于:
CONNECT mysquid.proxy:443 HTTP/1.1
所以最后使用了反向代理端口。
然而,在该端口上配置了一个 url_rewrite_program(一个 Perl 脚本)来过滤和更改特定 url 的某些路径,并且此类脚本错误地将请求重定向到一个不存在的 url在客户端中导致错误“503 服务不可用”。
我是 运行 本地 http 服务器和本地 squid 实例。本地 http 客户端打开一个连接到 squid 实例的套接字,这似乎可以正常工作。然后,我尝试通过发出以下 http 请求来连接到本地 http 服务器:
CONNECT localhost:80 HTTP/1.1\r\n
产生响应 headers
Content-Language en
Content-Length 3612
Content-Type text/html;charset=utf-8
Date Thu, 21 Jun 2018 17:28:10 GMT
Mime-Version 1.0
Server squid/3.5.27
Vary Accept-Language
X-Squid-Error ERR_DNS_FAIL 0
状态为 503。 我还尝试连接到 127.0.0.1,它产生了这个响应:
Content-Language en
Content-Length 3433
Content-Type text/html;charset=utf-8
Date Thu, 21 Jun 2018 17:35:16 GMT
Mime-Version 1.0
Server squid/3.5.27
Vary Accept-Language
X-Squid-Error ERR_CONNECT_FAIL 111
我的 squid.conf 看起来像这样:
http_port 3128
coredump_dir /var/spool/squid
acl SSL_ports port 443
acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 443 # https
acl Safe_ports port 1025-65535 # unregistered ports
acl CONNECT method CONNECT
acl any_host src all
acl all_dst dst all
http_access allow any_host
http_access allow all_dst
是否有不同的方式告诉 squid 连接到本地主机?
squid 试图以某种方式将 localhost
解析为 127.0.0.1
,但最终导致连接失败。但是,指定 [::1]
而不是 localhost
会按预期执行。
我发现 localhost
解析为 [::1]
而不是 127.0.0.1
的失败原因。
为了绕过 /etc/hosts/
只需将以下内容添加到 /etc/squid/hosts
:
127.0.0.1 localhost
然后 hosts_file /etc/squid/hosts
在你的 squid.conf
.
当然文件可以放在任何地方。
在我的例子中,我使用的是 squid 机器主机名(例如 mysquid.proxy),问题与 DNS 解析无关,因为 squid 机器可以自行解析正确使用其主机名。
问题是由同一代理中的额外端口配置引起的。我使用 squid 作为具有两个不同端口的正向代理和反向代理:
- 3128 - 正向代理
- 443 - 反向代理
客户端正在连接到(转发)代理 mysquid.proxy:3128 并且请求类似于:
CONNECT mysquid.proxy:443 HTTP/1.1
所以最后使用了反向代理端口。 然而,在该端口上配置了一个 url_rewrite_program(一个 Perl 脚本)来过滤和更改特定 url 的某些路径,并且此类脚本错误地将请求重定向到一个不存在的 url在客户端中导致错误“503 服务不可用”。