[英]How do I access my node.js server via public IP address?
I want to get a response from a remote node.js server by typing my public IP address into my browser.我想通过在浏览器中输入我的公共 IP 地址来从远程 node.js 服务器获得响应。 When I type my public IP into my browser on my personal computer, I get "Unable to Connect".
当我在个人计算机上的浏览器中键入我的公共 IP 时,我得到“无法连接”。 My node.js server isn't connected to the World =(
我的 node.js 服务器未连接到 World =(
var http = require('http');//create a server object:
http.createServer(function (req, res) {
res.write('Hello World!'); //write a response
res.end(); //end the response
}).listen(3000, function(){
console.log("server start at port 3000");
});
I've tried:我试过了:
I have zero idea what I'm doing wrong and would be so grateful for your help.我对自己做错了什么一无所知,非常感谢您的帮助。
I eventually found the answer, thanks to Saddy's suggestion that the problem might be port forwarding.我最终找到了答案,这要感谢 Saddy 的建议,即问题可能出在端口转发上。
1. I decided to use ports 3080 and 3443 for my node server.
2. I SSHed into my CentOs instance.
3. I disabled the default firewall, firewalld.
4. I set up port forwarding using iptables with the following commands:
firewalld stop防火墙停止
firewalld disable防火墙禁用
iptables -I INPUT 1 -p tcp --dport 80 -j ACCEPT iptables -I 输入 1 -p tcp --dport 80 -j 接受
iptables -I INPUT 1 -p tcp --dport 443 -j ACCEPT iptables -I 输入 1 -p tcp --dport 443 -j 接受
iptables -I INPUT 1 -p tcp --dport 25 -j ACCEPT iptables -I 输入 1 -p tcp --dport 25 -j 接受
iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3080 iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3080
iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 443 -j REDIRECT --to-port 3443 iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 443 -j REDIRECT --to-port 3443
iptables-save > /etc/sysconfig/iptables iptables-save > /etc/sysconfig/iptables
After this, I was able to access my node server via a browser.在此之后,我能够通过浏览器访问我的节点服务器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.