win10 排查curl: (7) Failed to connect to localhost port xx after 0 ms: Couldn‘t connect to server

win10 排查curl: (7) Failed to connect to localhost port xx after 0 ms: Couldn’t connect to server

产生问题环境

windows 10 下 通过 wsl 安装的 ubuntu 24.04

ubuntu curl -v http://localhost:8080/hello 出现的问题
lutong@CHINAMI-JD614UJ:~$ curl -v http://localhost:8080/hello
* Host localhost:8080 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
*   Trying [::1]:8080...
* connect to ::1 port 8080 from ::1 port 48296 failed: Connection refused
*   Trying 127.0.0.1:8080...
* connect to 127.0.0.1 port 8080 from 127.0.0.1 port 56166 failed: Connection refused
* Failed to connect to localhost port 8080 after 5 ms: Couldn't connect to server
* Closing connection
curl: (7) Failed to connect to localhost port 8080 after 5 ms: Couldn't connect to server

首先浏览器和 windows cmd curl 都是能访问通的

浏览器访问正常

在这里插入图片描述

windows cmd curl 都是能访问通的

在这里插入图片描述

思路1 端口是否被占用 sudo netstat -tunlp | grep 8080

lutong@CHINAMI-JD614UJ:~$ sudo netstat -tunlp | grep 8080
[sudo] password for lutong:
lutong@CHINAMI-JD614UJ:~$ sudo netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.54:53           0.0.0.0:*               LISTEN      135/systemd-resolve
tcp        0      0 127.0.0.1:6443          0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      135/systemd-resolve
tcp6       0      0 :::6379                 :::*                    LISTEN      -
tcp6       0      0 :::13316                :::*                    LISTEN      -
udp        0      0 127.0.0.54:53           0.0.0.0:*                           135/systemd-resolve
udp        0      0 127.0.0.53:53           0.0.0.0:*                           135/systemd-resolve
udp        0      0 127.0.0.1:323           0.0.0.0:*                           -
udp6       0      0 ::1:323                 :::*                                -
lutong@CHINAMI-JD614UJ:~$ sudo netstat -tunlp | grep 8080
lutong@CHINAMI-JD614UJ:~$

没看到8080 端口被占用的信息,不是端口的问题

思路2 防火墙没有开放8080 端口不能访问

1.首先windows 防火墙 控制面板\系统和安全\Windows Defender 防火墙 我尝试了开启和关闭 ,我用浏览器直接访问 和cmd curl 访问直接就能访问 通过,和 这个防火墙没关系
2. ubuntu ufw 防火墙

lutong@CHINAMI-JD614UJ:~$ sudo ufw status
Status: inactive

Status: inactive 防火墙没有启动

#开启防火墙
lutong@CHINAMI-JD614UJ:~$ sudo ufw enable
[sudo] password for lutong:
Firewall is active and enabled on system startup
#重启防火墙
lutong@CHINAMI-JD614UJ:~$ sudo ufw reload
Firewall reloaded
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值