ng serveの起動オプション

Angularを少し触っておくかと思い開発機(CentOS)のVagrant上にインストール。
public network経由で作業端末(非力なWindows)からつなごうと思っても接続を拒否された。

このサイトにアクセスできません

192.168.1.108 で接続が拒否されました。
192 168 108 4200 を Google で検索してください
ERR_CONNECTION_REFUSED

pingは通るけど、開発機(Vagrantのホスト)からもcurlでつながらない。vagrantに入ってチェックするとlocalhostなら繋がる。

curl http://192.168.1.108:4200
curl: (7) Failed connect to 192.168.1.108:4200; 接続を拒否されました

[root@localhost log]# curl http://localhost:4200
<!doctype html>
<html>
<head>
 <meta charset="utf-8">
 <title>TestWeb</title>
 <base href="/">

 <meta name="viewport" content="width=device-width, initial-scale=1">
 <link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
 <app-root>Loading...</app-root>
<script type="text/javascript" src="inline.bundle.js"></script><script type="text/javascript" src="polyfills.bundle.js"></script><script type="text/javascript" src="styles.bundle.js"></script><script type="text/javascript" src="vendor.bundle.js"></script><script type="text/javascript" src="main.bundle.js"></script></body>
</html>

ぐぐるとhostオプション付けないと、localhostしかlistenしないらしい

[root@localhost log]# netstat -anp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1/systemd
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1201/sshd
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1719/master
tcp        0      0 127.0.0.1:4200          0.0.0.0:*               LISTEN      3792/@angular/cli

ng serve –host 192.168.1.108
としておいて確認

[root@localhost log]# netstat -anp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1/systemd
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1201/sshd
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1719/master
tcp        0      0 192.168.1.108:4200      0.0.0.0:*               LISTEN      3827/@angular/cli

Local Addressに設定される。

調べる過程でSELinuxとFirewallとめた。

SELinuxは起動だけだとaudit.logに何もでていない。動作確認でハマりたくないのでpermissiveのまま時々auditみて確認ぐらいにしておく。

Firewallはportが空いていないので空けておく。(色々あける必要がでて面倒になったらFirewallとめたまま勉強する)

[vagrant@localhost ~]$ sudo firewall-cmd --list-ports --zone=public
(空欄)
[vagrant@localhost ~]$ sudo firewall-cmd --add-port=4200/tcp --zone=public --permanent
success
[vagrant@localhost ~]$ sudo firewall-cmd --reload
success
[vagrant@localhost ~]$ sudo firewall-cmd --list-ports --zone=public
4200/tcp

hostオプションのドキュメントはぱっとみ見つからなかったけど、いつものGoogleさんでドキュメントは無いものと考えたらいいのかな??

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です