【问题标题】:Linux Container (xenail) running react.js gives me Unable to Connect message when trying to connect to port 8080 from host尝试从主机连接到端口 8080 时,运行 react.js 的 Linux 容器(xenail)给了我无法连接的消息
【发布时间】:2017-12-01 03:37:21
【问题描述】:

我无法连接到我的 Linux Container 的网页。我正在关注 Udemy 关于 Reactjs 和 Redux 的课程,并从 Github 克隆了 ReduxSimpleStarter repo。

我运行 npm install 没有问题,然后运行 ​​npm start

jason@courses:~/udemy/react1/ReduxSimpleStarter$ npm start

> redux-simple-starter@1.0.0 start /home/jason/udemy/react1/ReduxSimpleStarter
> node ./node_modules/webpack-dev-server/bin/webpack-dev-server.js

http://localhost:8080/webpack-dev-server/
webpack result is served from /
content is served from ./
404s will fallback to /index.html
Hash: e1867813ff617d08f0b8
Version: webpack 1.15.0
Time: 10928ms
Asset    Size  Chunks             Chunk Names
bundle.js  746 kB       0  [emitted]  main
chunk    {0} bundle.js (main) 706 kB [rendered]
[0] multi main 28 bytes {0} [built]
[1] ./src/index.js 854 bytes {0} [built]
[2] ./~/react/react.js 56 bytes {0} [built]
[3] ./~/react/lib/React.js 1.49 kB {0} [built]
...
...
[198] ./~/invariant/browser.js 1.52 kB {0} [built]
[199] ./src/components/app.js 2.21 kB {0} [built]
[200] ./src/reducers/index.js 337 bytes {0} [built]
webpack: Compiled successfully.

我导航到lxc list显示的url地址,例如10.123.123.12

导航到 10.123.123.12:8080 让我“无法连接”

【问题讨论】:

    标签: node.js containers port react-redux linux-containers


    【解决方案1】:

    我终于解决了以下配置。

    在我的容器中,我使用 iptables 将端口 80 的传入流量重新路由到端口 8080。

    sysctl -w net.ipv4.conf.all.route_localnet=1
    iptables -t nat -I PREROUTING -p tcp --dport 80 -j DNAT --to 127.0.0.1:8080
    

    然后通过将 disableHostCheck : true 添加到 devServer 哈希来更改 webpack.config.js 文件。

    devServer {
      ...,
      ...,
      disableHostCheck: true
    }
    

    小心最后一条指令,因为它可能存在安全风险,但是,这是我笔记本电脑上的 Linux 容器,所以我不太担心。

    我现在可以导航到 10.123.123.12(不是 10.123.123.12:8080)并查看我的应用。

    【讨论】:

      猜你喜欢
      • 2012-06-05
      • 2012-07-05
      • 2021-11-28
      • 2017-02-11
      • 1970-01-01
      • 2022-11-16
      • 1970-01-01
      • 2020-02-15
      • 1970-01-01
      相关资源
      最近更新 更多