这个问题在 https://sourceforge.net/p/curl/bugs/1337/ 有说过。
原因是因为hosts中有把localhost解析成ipv6地址,curl先访问ipv6地址,不通再访问ipv4,但是curl有bug没有访问v4地址。
# 本地hosts
[root@MiWiFi-RA69-srv crm]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
# 测试
[root@MiWiFi-RA69-srv crm]# curl localhost:10080 ^C [root@MiWiFi-RA69-srv crm]# curl 127.0.0.1:10080 <html> <head><title>403 Forbidden</title></head> <body bgcolor="white"> <center><h1>403 Forbidden</h1></center> <hr><center>nginx/1.12.2</center> </body> </html>
方法1,通过指定-4参数强制走v4
[root@MiWiFi-RA69-srv crm]# curl localhost:10080 -4 <html> <head><title>403 Forbidden</title></head> <body bgcolor="white"> <center><h1>403 Forbidden</h1></center> <hr><center>nginx/1.12.2</center> </body> </html>
# 方法2,删掉ipv6再测试
[root@MiWiFi-RA69-srv crm]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 [root@MiWiFi-RA69-srv crm]# curl localhost:10080 <html> <head><title>403 Forbidden</title></head> <body bgcolor="white"> <center><h1>403 Forbidden</h1></center> <hr><center>nginx/1.12.2</center> </body> </html>
原创文章,转载请注明。本文链接地址: https://www.rootop.org/pages/4949.html