Reputation: 245
After server configuration, I had an IIS server listening on port 80 in my EC2 instance. I could access this from my elastic IP. But I turned off the IIS server hoping to launch my node server on port 80.
Now, both do not work !! My node application listens to port 80, but is not accessible from outside with the elastic IP. And I tried to start the IIS server in IIS manager, it looks like it turns on. But it not accessible within the instance (using private IP) or from outside.
What can I do to fix it ?
Thanks
Server.js
/*******************************************************************************************/
/*CREATE AND START SERVER*/
/*******************************************************************************************/
var fs = require('fs');
var html = fs.readFileSync('./public/index.html');
var server=http.createServer(function(req,res){
//res.write(html); // load the single view file (angular will handle the page changes on the front-end)
//res.end();
// application -------------------------------------------------------------
app.get('*', function(req, res) {
res.sendfile('./public/index.html'); // load the single view file (angular will handle the page changes on the front-end)
});
});
server.listen(80,'localhost');
Upvotes: 2
Views: 586
Reputation: 7553
I would recommend booting up a new instance with the same key pair and security group. Then move the Elastic IP over the the new instance.
To boot up Node JS Assuming AWS Linux AMI :
sudo yum update
sudo yum upgrade
sudo yum install gcc
yum groupinstall "Development tools"
wget -c https://nodejs.org/dist/v5.2.0/node-v5.2.0.tar.gz
#This is to download the source code.
tar -xzf node-v$ver.tar.gz
cd node-v$ver
./configure && make && sudo make install
Then your app.js :
var port = process.env.PORT || 80,
http = require('http'),
fs = require('fs'),
html = fs.readFileSync('index.html');
var index = require('./index');
var server = http.createServer(function (req, res) {
console.log(req.method + "sdf " + req.url + res);
if (req.method === 'POST') {
var body = '';
req.on('data', function(chunk) {
body += chunk;
});
req.on('end', function () {
res.writeHead(200, 'OK', {'Content-Type': 'text/plain'});
res.write (html);
res.end();
});
} else {
res.writeHead(200);
res.write(html);
res.end();
}
});
server.listen(port);
console.log('Server running at http://127.0.0.1:' + port + '/');
And your index.html :
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<p>Hello</p>
</body>
</html>
Thats just for a very simple instance of Node JS
For a more robust setup, I would recommend going to EBS and booting up one of their samples. It's much easier.
Hope this helps
Problem: User attempted to create http
server listening on port 80 and had express format running
Solution: use either http
listen to port or express
- both simultaneously will not allow the program to run
Upvotes: 1
Reputation: 141829
You still have the same problem as I described in the comments here.
When you do:
server.listen(80,'localhost')
You are telling the server to listen to requests from localhost, that means you are explicitly ignoring all external requests. Simply remove that argument to listen to requests from all addresses:
server.listen(80)
Upvotes: 0