无法访问React开发服务器:ERR_CONNECTION_REFUSED问题求助
React本地启动后浏览器无法连接,报错ERR_CONNECTION_REFUSED
我通过npm start在本地运行React应用,控制台显示服务启动编译成功,但Chrome、Firefox浏览器均无法连接,提示ERR_CONNECTION_REFUSED错误。
控制台输出如下:
Compiled successfully! You can now view frontend in the browser. Local: http://localhost:3000 On Your Network: http://192.168.0.12:3000 Note that the development build is not optimized. To create a production build, use npm run build. webpack compiled successfully
同时我在8000端口运行Django API服务器,通过setupProxy.js配置http-proxy-middleware做路由转发,代码如下:
import { createProxyMiddleware } from "http-proxy-middleware"; export default function (app) { app.use( "/api", createProxyMiddleware({ target: "http://localhost:8000", changeOrigin: true, }) ); }
已执行以下排查步骤:
- 检查URL拼写无误
- 确认React服务在3000端口、Django服务在8000端口正常运行
- 系统防火墙未阻止端口连接
- 重启过服务器和电脑
- 用多个浏览器测试过连接
- 浏览器控制台无报错信息
- 通过
lsof -i :3000确认3000端口无其他进程占用 - /etc/hosts中localhost配置正确
- 终端ping localhost响应正常
- 换3001端口启动React服务,问题依旧
- 尝试通过IP地址http://192.168.0.12:3000访问,还是无法连接
恳请帮忙解决该问题,谢谢!
内容的提问来源于stack exchange,提问作者Kjetil Bergtun
相关产品推荐
相关产品推荐

