angular-cli: ng serve doesn't listen other than localhost
- OS? Windows 7, 8 or 10. Linux (which distribution). Mac OSX (Yosemite? El Capitan?)
Ubuntu 16.04
- Versions. Please run
ng --version
. If there’s nothing outputted, please run in a Terminal:node --version
and paste the result here:
node --version
v6.6.0
- Repro steps. Was this an app that wasn’t created using the CLI? What change did you do on your code? etc.
I have this app https://github.com/jelbourn/material2-app.
And just type npm start
in repository root. Both in remote and local machine, I see
> m2-app@0.0.0 start /home/gyuho/material2-app
> ng serve
Could not start watchman; falling back to NodeWatcher for file system events.
Visit http://ember-cli.com/user-guide/#watchman for more info.
** NG Live Development Server is running on http://localhost:4200. **
8221ms building modules
23ms sealing
0ms optimizing
1ms basic module optimization
97ms module optimization
0ms advanced module optimization
11ms basic chunk optimization
0ms chunk optimization
2ms advanced chunk optimization
0ms module and chunk tree optimization
150ms module reviving
2ms module order optimization
5ms module id optimization
3ms chunk reviving
0ms chunk order optimization
13ms chunk id optimization
83ms hashing
1ms module assets processing
188ms chunk assets processing
5ms additional chunk assets processing
0ms recording
0ms additional asset processing
2415ms chunk asset optimization
1616ms asset optimization
37ms emitting
Hash: 93c935dc7d6ef86a5d1e
Version: webpack 2.1.0-beta.22
Time: 12902ms
Asset Size Chunks Chunk Names
main.bundle.js 3.43 MB 0, 2 [emitted] main
styles.bundle.js 43.4 kB 1, 2 [emitted] styles
inline.js 5.53 kB 2 [emitted] inline
main.map 3.5 MB 0, 2 [emitted] main
styles.map 53.8 kB 1, 2 [emitted] styles
inline.map 5.59 kB 2 [emitted] inline
index.html 580 bytes [emitted]
Child html-webpack-plugin for "index.html":
Asset Size Chunks Chunk Names
index.html 2.92 kB 0
webpack: bundle is now VALID.
But when I try to connect to http://[PUBLIC_IP_ADDRESS_OF_CLOUD]:4200
, it doesn’t serve. I checked all network settings (I am using Google Cloud VM) and confirm that there’s no firewall blocking :4200
.
Same simple webserver in Go listening to :4200
works fine on the same machine.
Is there anything that I am missing to deploy angular app in virtual machines?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 9
- Comments: 23
Commits related to this issue
- *: use --host flag, enable prod https://github.com/angular/angular-cli/issues/2375 — committed to etcd-io/etcdlabs by gyuho 8 years ago
Works with command
ng serve --host 0.0.0.0
@sshreya0808 I may have had the same “Invalid Host Header” problem as you did. The cause of this problem may or may not have been because AWS remote server/VPS has some default firewalls/security settings that may happen to obstruct simply testing Angular’s CLI-installed “Welcome to app!” page. To fix this on my AWS instance, without enabling production, I simply ran:
ng serve --port 8080 --host 0.0.0.0 --disableHostCheck true
, then navigated from Safari/Chrome to the IP address I associated with my instance in the “Elastic IPs” section of my AWS dashboard – plus the port I specified (e.g. “142.43.53.12:8080/”).@levivel yeah,
ng serve --port 8080 --host 0.0.0.0 --disableHostCheck true
it works for me. thanks 👍@ninjadev1030 solution with
--host 0.0.0.0 --disableHostCheck true
works even in Angular 6! Thanks for this.@gyuho Hi have you found the cause which package or making the app bind to 127.0.0.1 and not other IPs? I have to run --host 0.0.0.0 as well to make it work on VM.
Also worked for me by ading
serve
on .angular-cli.json. Port here 4201. Solution found from #2542. “defaults”: { “styleExt”: “css”, “component”: {}, “serve”: { “host”: “0.0.0.0”, “port”: 4201 } }Thanks It worked 😄 ng serve --host 0.0.0.0
Invalid Host header. still not solved by ng serve --host 0.0.0.0