httpproxylocalhostsquid

Squid DNS FAIL when trying to connect to localhost


I'm running a local http server and local squid instance. A local http client opens a socket connecting to the squid instance, which seems to work. I then try to tunnel to the local http server by issuing the following http request:

CONNECT localhost:80 HTTP/1.1\r\n

which yields the response 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

with status 503. I also tried connecting to 127.0.0.1, which yields this response:

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

My squid.conf looks like this:

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

Is there a different way to tell squid to connect to localhost?


Solution

  • Somehow squid tried to resolve localhost to 127.0.0.1, which ended up in a connection failure. Specifying [::1] instead of localhost, however, performs as expected.