Cyril
Cyril

Reputation: 167

How do I make a web server accessible though the internet?

I have created a basic web server using node.js which listens to port 3000 on my desktop. It serves static HTML files (jQuery mobile documents actually).

I am able to access the site on the local host (my Windows 7 desktop) using http://127.0.0.1:3000/.

I want to be able to access the site from my mobile over the internet.

Is there a way this can be done?

Upvotes: 1

Views: 2644

Answers (5)

Olivier Coilland
Olivier Coilland

Reputation: 3096

Ok, old question but for future me, you can nowadays use ngrok

Secure tunnels to localhost

”I want to expose a local server behind a NAT or firewall to the internet.”

Of course not for production, but perfect to develop webhooks!

Upvotes: 1

alandarev
alandarev

Reputation: 8635

Flexible solution (not for production, but easy, and without need to configure routers) is using localhost tunnel services, since you are on node.js, there is already one available:

localtunnel. To use it:

  1. npm install -g localtunnel
  2. lt --port 3000
  3. Share the url it provides

Reasoning against using it in production:

  1. You rely on good-will of the intermediate service. Clients will communicate with that 'tunnel', and who knows whether it is sniffing the sensitive data, or injects some information. Probably not, but you will never be given a guarantee.
  2. Down-time of this tunnel service will affect you. As it is free, I would expect the service quality as high as the money you pay for it.
  3. The overall idea of those localhost tunnels is for easier development process. Letting your friends see the site and give a feedback without much of a hassle. It might even be against their policy to run a high-load website through a tunnel.

Upvotes: 2

Mahmal Sami
Mahmal Sami

Reputation: 709

What you are trying to do is not a safe and secure option.
As you're using nodejs, have you considered deploying your app as PaaS plateform as heroku.com ?
The options listed are all functional, but not recommended: You need to use an external service to serve your files.

Upvotes: 0

Nathan Romano
Nathan Romano

Reputation: 7096

I like to use nginx, Here is an example.

upstream app_myapp {
server 127.0.0.1:8080;
}

server {
listen 0.0.0.0:80;
server_name www.myhost.com myhost.com;

location / {
    auth_basic "Restricted";
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_set_header X-NginX-Proxy true;

    proxy_pass http://app_myapp/;
    proxy_redirect off;

    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
}

Upvotes: 0

durbnpoisn
durbnpoisn

Reputation: 4669

Look into port forwarding on your router. Set the port forward for HTML requests to 3000. Then find out what your router's IP address is.

Then use http://[routerIP]:port/ to access your site.

And pray you don't get hacked like mad for opening up that port with no security.

Upvotes: 0

Related Questions