Question

Access node based web server with public IP

Posted July 22, 2017 11k views
Ubuntu Node.js

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?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

2 answers

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.

Submit an Answer