Reputation: 13151
I created Angular app on EC2 (RHEL 7) with ng new app1
and tried to serve it with:
ng new app1
cd app1
ng serve --port=4200
When I go to url: IP:4200
- getting following error:
Exception: tcp_error
Exception details: A communication error occurred: "Connection refused"
But when I try with NodeJS on the same server and same port - I can see the result on the same IP:4200
. NodeJS code is:
var express = require('express');
var app = express();
app.get('/', function (req, res) {
res.send('Hello World 3!');
});
app.listen(4200, function () {
console.log('Example app listening on port 4500!');
});
What could be wrong with Angular and EC2? I can run the exact same Angular code on my local computer and when go to localhost:4200
- I can see results (but not from EC2 IP:4200
).
Upvotes: 0
Views: 1191
Reputation: 11
To locate the issue.
Upvotes: 1
Reputation: 23065
According to the output of netstat
, Angular's server is configured to listen only for connections that target the ip 127.0.0.1
.
But connections from outside will target a different IP, so you need to pass that other IP with the --host
param. Or, to make it easier, use the IP 0.0.0.0
which means "every IP that this host responds to".
So the command should be like:
ng serve --port=4200 --host=0.0.0.0
Upvotes: 4