【问题标题】:Can't access create-app-react app via local network无法通过本地网络访问 create-app-react 应用程序
【发布时间】:2020-05-07 11:48:15
【问题描述】:

我从浏览器访问默认反应页面时遇到问题。 React 应用在 VM 上启动,通过桥接网络连接到主机操作系统。

VM 上的网络设置 (CentOS 7)

2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:ef:79:7b brd ff:ff:ff:ff:ff:ff
    inet 192.168.2.18/24 brd 192.168.2.255 scope global noprefixroute dynamic ens33
       valid_lft 19371sec preferred_lft 19371sec
    inet6 fe80::da52:a805:4b32:ca69/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

主机操作系统 (Windows 10) 上的网络设置

   Description. . . . . . . . . . . . . : Intel(R) Dual Band Wireless-AC 7265
   MAC Address. . . . . . . . . : 7C-B0-C2-DF-7F-F5
   DHCP enabled. . . . . . . . . . . : Yes
   IPv4-address. . . . . . . . . . . . : 192.168.2.12(Primary)
   Network Mask. . . . . . . . . . : 255.255.255.0
   Default-gateway. . . . . . . . . : 192.168.2.1
   DHCP-server. . . . . . . . . . . : 192.168.2.1
   DNS-server. . . . . . . . . . . : 192.168.2.1
   NetBios TCP/IP. . . . . . . . : Enabled

我可以毫无问题地从主机操作系统 ping VM 地址(俄语字母,抱歉)

C:\Users\vud>ping 192.168.2.18

    Обмен пакетами с 192.168.2.18 по с 32 байтами данных:
    Ответ от 192.168.2.18: число байт=32 время<1мс TTL=64
    Ответ от 192.168.2.18: число байт=32 время<1мс TTL=64
    Ответ от 192.168.2.18: число байт=32 время<1мс TTL=64

所以我在 VM 上创建了一个测试前端项目:

[vud@centos~] create-app-react frontend

我从前端目录开始命令:

[vud@centos frontend]$ npm start

这告诉我服务器启动成功:

Compiled successfully!

You can now view frontend in the browser.

  Local:            http://localhost:3000
  On Your Network:  http://192.168.2.18:3000

Note that the development build is not optimized.
To create a production build, use npm run build.

但我无法从 Windows 10 的浏览器访问它,得到一个 connection timeout

不过,这很有趣,因为我可以从 VM 卷曲页面内容:

curl output

所以,在尝试从主机操作系统通过浏览器访问反应页面时,我还使用 tcpdump 检查了端口 3000 上的流量:

[vud@centos frontend]$ sudo tcpdump -i ens33 host 192.168.2.12 and port 3000 
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytes
21:36:09.886531 IP 192.168.2.12.56517 > centos.hbci: Flags [S], seq 2766461791, win 8192, options [mss 1460,nop,wscale 8,nop,nop,sackOK], length 0
21:36:10.137042 IP 192.168.2.12.56518 > centos.hbci: Flags [S], seq 4251361662, win 8192, options [mss 1460,nop,wscale 8,nop,nop,sackOK], length 0
21:36:12.886743 IP 192.168.2.12.56517 > centos.hbci: Flags [S], seq 2766461791, win 8192, options [mss 1460,nop,wscale 8,nop,nop,sackOK], length 0
21:36:13.137883 IP 192.168.2.12.56518 > centos.hbci: Flags [S], seq 4251361662, win 8192, options [mss 1460,nop,wscale 8,nop,nop,sackOK], length 0
21:36:18.887182 IP 192.168.2.12.56517 > centos.hbci: Flags [S], seq 2766461791, win 8192, options [mss 1460,nop,nop,sackOK], length 0
21:36:19.138951 IP 192.168.2.12.56518 > centos.hbci: Flags [S], seq 4251361662, win 8192, options [mss 1460,nop,nop,sackOK], length 0

SELINUX 被禁用了,顺便说一句

[vud@centos frontend]$ cat /etc/selinux/config 

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted 

由于某种原因,VM 主机不接受连接。有没有办法浏览嵌入式网络服务器的日志?我正在使用这个应用程序作为学习 docker 的一种手段,所以我对 react/js/npm 完全不熟悉。

附:我访问了类似的主题,但他们并没有真正给我答案。

【问题讨论】:

  • 您能否尝试在浏览器http://192.168.2.18:3000 中搜索此内容,如果不起作用,请告诉我您运行 npm start 的 PC 或 VM 的 IP 地址是什么跨度>
  • 当然,我试过关注这个地址,并在我的帖子中附上截图。 192.168.2.18 是安装了 npm 的 VM 的地址 192.168.2.12 是主机操作系统的 IP 地址

标签: reactjs centos7 create-react-app


【解决方案1】:

好的,禁用firewalld解决了问题

systemctl stop firewalld

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-10-15
    • 1970-01-01
    • 1970-01-01
    • 2021-06-06
    • 2022-12-30
    • 2017-10-20
    相关资源
    最近更新 更多