Check if your host is listening on port 8080:
$netstat -ntlp | grep 8080
题
I have set up a Vagrant box with Ubuntu 14.04, node.js, npm, mongodb, forever, deployd and express. I forwarded the host port 8080 to guest port 80, and have a node server in the guest machine listening on port 80.
When I visit http://localhost:8080
in my browser, I expect to see the output from my node server ("Hello World") but instead I get no response from the browser.
From inside the guest machine, when I attempt to curl, I get curl: (7) Failed to connect to localhost port 80: Connection refused
.
From the host machine, when I attempt to curl, I get curl: (52) Empty reply from server
.
I have tried allowing all incoming web traffic by modifying the iptables using sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
, and have saved those settings and restarted the machine using vagrant reload
. That did not resolve the issue.
My Vagrantfile looks like this:
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.provision :shell, :path => "bootstrap.sh"
config.vm.network "forwarded_port", guest: 80, host: 8080
end
My provisioning script looks like this:
#!/usr/bin/env bash
apt-get update
apt-get upgrade
apt-get install -y python-software-properties python g++ make
add-apt-repository ppa:chris-lea/node.js
apt-get update
apt-get install -y nodejs
export NODE_PATH=$NODE_PATH:/usr/lib/node_modules/
apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list
apt-get update
apt-get install -y mongodb-10gen
npm install forever -g
npm install deployd -g
npm install express -g
mkdir /data
mkdir /data/db
rm -rf /var/www
ln -fs /vagrant /var/www
I am running forever start server.js
to start up this sample node server:
var http = require("http");
http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}).listen(80);
What am I missing here? Thanks in advance...
解决方案
Check if your host is listening on port 8080:
$netstat -ntlp | grep 8080