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

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.

That should be easy to check; what is your region?

I am in UAE so I choose the option region option "Asia/Pacific" in the plugin.
how can I check It?

You can check it by changing to another region. But I don't think that will change much.

I think this may be caused by a newer version of the ngrok python binding used by the plugin. I'll look in to that.

1 Like

I think I have fixed the issue. Are you running OctoPrint on Python 3 (if so, good for you!)? And did you install the ngrok plugin after the 25th of October?

I am new to octopi, I have set it up just recently (2 month ago), not sure how to check for the python version on octopi but I'm running version 1.4.2.
for the ngrok plugin i have tried to re-install it 10 days ago.

I have tried today the new update that you published (0.3.1) also I face the same issue.