Ngrok Tunnel: A more secure but simple to use alternative to port forwarding

That looks like the previous tunnel wasn't properly closed, and therefore still existed on the NGROK server side and wouldn't allow you to create a second one. You might have to log in to the NGROK dashboard and kill the tunnel manually.

Thanks for the partial logs. Thus tells me a little what happened. A more complete log might give me an indication of why or how it happened so I can try to reproduce the issue and fix it.

Well i thought this was enough information. But here you go.
octoprint.log (134.0 GB)
Does a function exists were you can terminate a tunnel?

You can always close the tunnel from the ngrok.io dashboard. However I will try to detect orphan tunnels in a future version.

Hey fieldOfView, I recently downloaded this plugin and I think its great! I am having one issue that i haven't been able to figure out.

The live stream of the webcam is inaccessible on WAN, but works on LAN.
I've used a few different URLs to try and get it to work.
http://127.0.0.1:8080/?action=stream
http://192.168.0.xxx:8080/?action=stream
http://ender3.local:8080/?action=stream

all work locally but not through the tunnel for some reason. Any tips?

Have you tried a relative URL, ie /webcam/?action=stream

Yup no luck

Yeah, I remembered this issue after writing that reply...

Ah thanks! I'm using raspian with octoprint so i dont have a proxy set for the cam. i'll give it a go and see what happens.

Setting up a proxy so that both OctoPrint and the webcam are accessible from the same port (which is not the native OctoPrint port) is indeed the way to go. This will allow you to have a single configuration that works both locally and through the ngrok tunnel. It is also how OctoPi comes by preconfigured.

So this is the exact config i'm using for my ha proxy.

global
        maxconn 4096
        user haproxy
        group haproxy
        daemon
        log 127.0.0.1 local0 debug

defaults
        log     global
        mode    http
        option  httplog
        option  dontlognull
        retries 3
        option redispatch
        option http-server-close
        option forwardfor
        maxconn 2000
        timeout connect 5s
        timeout client  15min
        timeout server  15min

frontend public
        bind *:80
        use_backend webcam if { path_beg /webcam/ }
        default_backend octoprint

backend octoprint
        option forwardfor
        server octoprint1 127.0.0.1:5000

backend webcam
        reqrep ^([^\ :]*)\ /webcam/(.*)     \1\ /\2
        server webcam1  127.0.0.1:8080

for the webcam URL setting i'm using

/webcam/?action=stream
1 Like

So @fieldOfView I have a standard octopi setup and I experience the same thing using haproxy and the relative URL to webcam address. Haven't really dug into it much since I personally connect differently.

The ngrok plugin looks at what publicPort is configured to use in the discovery section of the settings. For OctoPi, this is normally set to port 80. For manual installs, it is normally set to port 5000. Port 5000 skips the reverse proxy, so the webcam "redirect" is also requested from port 5000. Could you try setting the publicPort to 80? You may have to manually edit config.yaml for that.

Thanks for that information @fieldOfView. It seems that has to be manually set, even in default octopi instance, because the default setting within OctoPrint based on this is that it will use the port OctoPrint was started on, which by default is 5000.

Not with OctoPi; I am fairly sure that gets preset to port 80 here:

Though that does leave the question how it was set to port 5000 on your setup. Did you perhaps at some point remove your config.yaml to have it recreated from scratch by OctoPrint?

I think I can at least make a check for this configuration, or at least have the portnumber configurable.

I wasn't using octopi, I was using default raspbian and added octoprint so I think I just didn't configure it correctly. I went ahead and deleted the old partition and used the octopi image working fine now. Thanks for all the help guys

Yeah, there's no telling on this pi, it's running an older nightly build of octopi 0.18 and there is a good chance during testing something I deleted that config.yaml.

Hey fieldOfView, thanks for the awesome work.

I have downloaded the plugin recently and it is working fine.
but I believe that the basic authentication is not working for me, when I'm accessing the ngrok link there is no username and password are popping up from the browser, it will open directly the login page of octoprint.
is this behavior is right? or did I miss configure the plugin?

Hi @nori0aw, sorry I missed this comment. The tunnel should ask for a username and password. However, once you have entered that, your browser may remember the username and password (or actually the "session") until you restart the browser. Could you try closing all browser windows and opening the tunnel again? Could you try a different browser and/or your browser incognito mode?

Continuing the discussion from Ngrok Tunnel: A more secure but simple to use alternative to port forwarding:

Hi @fieldOfView, thank you for your reply,
I have tried to restart both the Octopi system & the browser with incognito at the same time and still no luck. I also will tried to uninstall and reinstall the plugin with the same result.
I think it's an issue with Ngrok in my region.