jaibatrik
By:
jaibatrik

Access node based web server with public IP

July 22, 2017 461 views
Node.js Ubuntu

I have installed a node based lightweight web server https://www.npmjs.com/package/http-server in my droplet and trying to serve a directory with it.

mkdir web
cd web
http-server

This shows the output as -

Starting up http-server, serving ./
Available on:
http://127.0.0.1:8080
http://139.59.71.167:8080
http://10.47.0.5:8080

But when I try to access http://139.59.71.167:8080 from my browser, it times out. However, logging in to another terminal via ssh and running curl http://139.59.71.167:8080 gets the output.

Could anyone please indicate what I need to do to access the server from outside the network?

3 Answers
hansen July 22, 2017
Accepted Answer

Hi @jaibatrik

Can you check if your firewall is active?

sudo ufw status

And run this command to show listening services:

sudo lsof -iTCP -sTCP:LISTEN -P
  • On running sudo ufw status, I get the following -

    Status: active
    
    To                         Action      From
    --                         ------      ----
    22                         LIMIT       Anywhere                  
    80                         ALLOW       Anywhere                  
    443                        ALLOW       Anywhere                  
    22 (v6)                    LIMIT       Anywhere (v6)             
    80 (v6)                    ALLOW       Anywhere (v6)             
    443 (v6)                   ALLOW       Anywhere (v6)  
    

    I see that 8080 is not listed here. Running sudo lsof -iTCP -sTCP:LISTEN -P gives the following -

    COMMAND  PID      USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
    sshd    1875      root    3u  IPv4  18383      0t0  TCP *:22 (LISTEN)
    sshd    1875      root    4u  IPv6  18392      0t0  TCP *:22 (LISTEN)
    node    2536 jaibatrik   12u  IPv4  22839      0t0  TCP *:8080 (LISTEN)
    

    Here, I can see an entry for node.

I use vpn service to protect my online privacy. In my life I often use VPN, especially during trip to different countries, where some sites were blocked. But sometimes vpn can work bad. In this case I use one service tool what is my ip which can help to know the vpn efficient .

Have another answer? Share your knowledge.