User Tools

Site Tools


reverse_proxy_multiple_octoprint_instances_with_nginx

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
reverse_proxy_multiple_octoprint_instances_with_nginx [2025/11/30 21:03] – created tkbletscreverse_proxy_multiple_octoprint_instances_with_nginx [2025/11/30 21:14] (current) tkbletsc
Line 5: Line 5:
 Normally, setting this up a reverse proxy is straightforward, but the weird webcam support in Octoprint makes this a little tricky. Normally, setting this up a reverse proxy is straightforward, but the weird webcam support in Octoprint makes this a little tricky.
  
-First, install nginx per normal, and set up a basic domain config in /etc/nginx/sites-available/<your_domain>. You can enable HTTPS at this time with certbot. That's all out of scope for us.+First, install nginx per normal, and set up a basic domain config in ''/etc/nginx/sites-available/<your_domain>''. You can enable HTTPS at this time with certbot. That's all out of scope for us.
  
-Next, edit the web server ''/etc/nginx/sites-available/''. This example shows two Octoprint instances (with two location blocks per instance):+Next, edit the web server ''/etc/nginx/sites-available/<your_domain>''. This example shows two Octoprint instances (with two location blocks per instance):
 <file> <file>
     location ~ ^/webcam/(.*) {     location ~ ^/webcam/(.*) {
Line 17: Line 17:
             rewrite ^ https://$host$uri permanent;             rewrite ^ https://$host$uri permanent;
         }         }
 +        # require login
         auth_basic           "OctoPrint: PrintrBot";         auth_basic           "OctoPrint: PrintrBot";
         auth_basic_user_file /etc/nginx/passwd-3dprinter.conf;         auth_basic_user_file /etc/nginx/passwd-3dprinter.conf;
 +        
 +        # proxy
         rewrite ^/printrbot/(.*)$ /$1 break;         rewrite ^/printrbot/(.*)$ /$1 break;
         proxy_pass http://192.168.0.42;         proxy_pass http://192.168.0.42;
Line 33: Line 36:
  
         location /printrbot/webcam/ {         location /printrbot/webcam/ {
-            auth_basic off;+            auth_basic off; # no login for just the webcam
             rewrite ^/printrbot/webcam/(.*)$ /webcam/$1 break;             rewrite ^/printrbot/webcam/(.*)$ /webcam/$1 break;
             proxy_pass http://192.168.0.42;             proxy_pass http://192.168.0.42;
Line 49: Line 52:
             rewrite ^ https://$host$uri permanent;             rewrite ^ https://$host$uri permanent;
         }         }
 +        # require login
         auth_basic           "OctoPrint: Prusa";         auth_basic           "OctoPrint: Prusa";
         auth_basic_user_file /etc/nginx/passwd-3dprinter.conf;         auth_basic_user_file /etc/nginx/passwd-3dprinter.conf;
 +        
 +        # proxy
         rewrite ^/prusa/(.*)$ /$1 break;         rewrite ^/prusa/(.*)$ /$1 break;
         proxy_pass http://192.168.0.46;         proxy_pass http://192.168.0.46;
Line 65: Line 71:
  
         location /prusa/webcam/ {         location /prusa/webcam/ {
-            auth_basic off;+            auth_basic off; # no login for just the webcam
             rewrite ^/prusa/webcam/(.*)$ /webcam2/$1 break;             rewrite ^/prusa/webcam/(.*)$ /webcam2/$1 break;
             proxy_pass http://192.168.0.46;             proxy_pass http://192.168.0.46;
Line 73: Line 79:
  
 </file> </file>
 +
 +Then ''systemctl reload nginx''.
  
 Things to note: Things to note:
  
-  * Octoprint (as configured in an Octopi install) expects the webcam to be at /webcam -- an absolute URL. +  * Webcam stuff: 
-  * Thus, the first "location ~ ^/webcam/(.*)" to rewrite it under the new URL. +    * Octoprint (as configured in an Octopi install) expects the webcam to be at /webcam – an absolute URL. 
-  * Because //all// Octoprint instances expect their webcam to be at /webcam, we need to tweak things a bit. +    * Thus, the first "location ~ ^/webcam/(.*)" to rewrite it under the new URL. 
-  * The second Octoprint will map /webcam2 instead of just /webcam; we'll change the config on that instance as well to allow this +    * Because //all//  Octoprint instances expect their webcam to be at /webcam, we need to tweak things a bit. 
-  * (Note: if you have just once octoprint instance, then you can skip the following steps, and you should be done)+    * The second Octoprint will map /webcam2 instead of just /webcam; we'll change the config on that instance as well to allow this 
 +    * (Note: if you have just once octoprint instance, then you can skip the following steps, and you should be done) 
 +  * Auth stuff: 
 +    * The above config requires HTTP auth for the main interface, but explicitly allows the webcam without auth. 
 +    * This way you can stream the webcams from a plain page to anyone, but login requires auth. 
 +    * You can omit "auth_basic off" to require auth for both. 
 +    * You can omit all the "auth_basic" entirely to disable auth for both. 
  
 ===== Enabling webcam support for Octoprint instances after the first ===== ===== Enabling webcam support for Octoprint instances after the first =====
Line 86: Line 100:
 We want to tweak each octoprint instances after the first as follows to give it a unique absolute URL to the webcam. This assumes Octoprint is installed as in Octopi. We want to tweak each octoprint instances after the first as follows to give it a unique absolute URL to the webcam. This assumes Octoprint is installed as in Octopi.
  
-Edit ''/etc/haproxy/haproxy.cfg'', and add the two noted lines:+Edit ''/etc/haproxy/haproxy.cfg'', and add the two noted lines, with a new number (or other URL tweak) per instance:
  
 <file> <file>
Line 99: Line 113:
 </file> </file>
  
 +Then ''systemctl reload haproxy''.
 +
 +Then, in Octoprint web UI, go to configuration, and in the "Classic Webcam" section, change Stream URL from ''/webcam/?action=stream'' to ''/webcam2/?action=stream'' (or whatever tweaked URL you did for this instance).
  
 +When done, the full UI including webcam should function both via direct connection to each Octoprint instance as well as via the URLs on the nginx proxy. 
reverse_proxy_multiple_octoprint_instances_with_nginx.1764565418.txt.gz · Last modified: by tkbletsc

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki