localtunnel / server

server for localtunnel.me
https://localtunnel.me
MIT License
3.01k stars 976 forks source link

LocalTunnel server on DigitalOcean droplet with Ubuntu help #141

Open gaamaaresosa opened 3 years ago

gaamaaresosa commented 3 years ago

I am trying to run this localtunnel server on my DigitalOcean droplet with Ubuntu. I added a domain on this droplet. http://examplesite.in

I installed as below: git clone git://github.com/defunctzombie/localtunnel-server.git cd localtunnel-server npm install

When I run this command I got some error : bin/server --port 1234 Then I installed : apt install golang-golang-x-tools -y Again run this command and no error : bin/server --port 1234

I get this response on the putty. Defaulting to port 8080Listening on port 8080

Is this the expected response on success ?

Then on my raspberry pi if I run this command: lt --host http://examplesite.in:1234 -p 3000 nothing is happening and I don't get any url.

I am sure only few more steps for success which I don't know that.

I wonder this localtunnel works great on localtunnel.me server. Also given open source code. But no step by step tutorial for freshers like me to run our own server in DigitalOcean like cloud.

"You can set up DNS entries for your domain.tld and .domain.tld (or sub.domain.tld and .sub.domain.tld)." "The server can accept incoming TCP connections for any non-root TCP port (i.e. ports over 1000)." I couldn't understand what it is. It it nothing but normal domain.com or domain.in ?

Can any one make a step by step tutorial to may our own server in DigitalOcean droplet ?

micahbule commented 3 years ago

Okay. Managed to make this work under a subdomain using the instructions below. Figured this should also work if you're using the main domain for the server, so I'm posting it here. While your setup may not be similar, consider the following steps and tweak depending on your process:

  1. Register a wildcard subdomain entry on your DNS records. Depending on your registrar, this is normally allowed and should be as easy as adding an A record with *.domain.tld as your host. In my case, I want to set the server up under a subdomain, so I had to register both the main subdomain lt.my-domain.com and wildcard subdomain *.lt.my-domain.com.
  2. Login to your DigitalOcean droplet via SSH and set up your reverse proxy. In my case, I used Nginx for my web server and configured it as a reverse proxy for the LocalTunnel server. Since LocalTunnel server is basically just another NodeJS app, you can actually follow DO's guide on setting up Nginx as a reverse proxy for NodeJS applications. I'm also running several NodeJS applications on the same web server, so I had to configure it like a virtual host, listening to other ports -- otherwise if you will be using a dedicated server for the tunneling service, it's totally fine to just use port 80.
  3. Setup SSL for your main domain/subdomain and wildcard subdomain. You can use Let's Encrypt for this one, but there's a specific command to generate an SSL for both the main domain/subdomain and wildcard subdomain. I followed this guide for the specific command.
  4. While I theoretically think this will run under PM2 or even systemd, I'm only executing it as a regular NodeJS app with the following command for two reasons: node -r esm ./bin/server --port <port_number> --domain lt.my-domain.com --secure
    • The package is using ES6 modules. Without a compiler like Babel, it won't run on its own hence the need to execute node -r esm. I don't wanna hassle myself into figuring it out -- yet.
    • I'm not gonna use the service very often, so I'm only executing it from the command line instead of executing it as a daemon service
  5. DigitalOcean droplets does not block any port nor have any firewall configurations by default, so if you've set it up right, you should have a working LocalTunnel server at this point. All you need to do is run a LocalTunnel client from your local machine. In my case, I installed LocalTunnel as a global module so I just need to execute lt --host lt.my-domain.com --port <local_port>. Tested it with the --subdomain command as well to reserve a specific subdomain for the tunnel and it works as is.

Hope that helps.

gaamaaresosa commented 3 years ago

Thanks micahbule I will check this well later. Time being I managed many things by my own. Thanks again for your detailed help.

micahbule commented 3 years ago

Update: Managed to install it as a docker image on my server using the instructions on README -- of course passing in the --domain and --secure flag, as well as specifying the specific port that my Nginx reverse proxy is forwarding requests to.

garudaonekh commented 3 years ago

@micahbule I also managed to get it working on DO using Ubuntu. But the main problem is it is not working properly. most of the time, i got 404 error and another issue is cannot request a new subdomain from the server after client restart. my client is Raspberry Pi. Any suggestion to improve this?

micahbule commented 3 years ago

@micahbule I also managed to get it working on DO using Ubuntu. But the main problem is it is not working properly. most of the time, i got 404 error and another issue is cannot request a new subdomain from the server after client restart. my client is Raspberry Pi. Any suggestion to improve this?

It takes time for the server to clear any used subdomains for some reason, haven't really dived into it. Not entirely sure as well why you're getting a 404. Maybe check the service you're tunnelling first?

JamesBotterill commented 1 year ago

This was a great help though the biggest issue was the DO ngnix docs being outdated and missing a step:

Once you've created your server config in the /etc/nginx/sites-available/domain.com you need to link it to the sites-enabled with the following command

sudo ln -s /etc/nginx/sites-available/domain /etc/nginx/sites-enabled/