Hosting a web page

Is it possible to host a web page at the same time as Octoprint?
I imagine that might cause security issues if it was public, but I'm thinking for just within the household.

Sure, you can set up nginx or apache on the same computer as the one you are running. Or you can start your own small http server with a Python script. But OctoPrint has no built-in functionality to host files other than its own dynamic and static content.

I had a problem starting the apache server, I'd assumed it was in conflict with Octoprint, not least because the instructions tell you to point your browser at the IP address, which is where the Octopi server lives...

What port are you starting apache on? If you are trying to use port 80, make sure that you don't have eg HAProxy forwarding port 80 to OctoPrint; no two services can use the same port at the same time.

On a general note, if you say "I had a problem..." without saying what the problem was, all we can do is guess. Our guess may be accurate, or it may be a waste of time.

You can actually create a UIPlugin mixin implementation, or possibly work with a HTTRoute hook in a plugin for it to serve a specific page you upload.

Sorry, I added an edit, but forgot to post it.

The problem that I'd had was "Config variable ${APACHE_RUN_DIR} is not defined", which I'm sure I can find the answer to if I read the instructions more carefully, but the thing with the IP address led me to the opinion that I needed to ask someone who knows.

Sorry jneilliii, that's Greek to me. :?

I guess the bigger question is what are you trying to display? If you just want to give them read only access to octoprint you can do that with granular permissions in the latest octoprint version.

I want to display some information that is totally unrelated to Octoprint.
It's just that Octopi is what's on the hardware.
A todo list and rota for the household perhaps?

Yeah, your best bet is to get a web server running on its own port. A default octopi image is already using port 5000 (octoprint web server), 8080 (webcam streamer), 80 (unsecure haproxy), and 443 (secure haproxy). If you bind Apache to port 8081 for example, you can then edit /etc/haproxy/haproxy.cfg to redirect a specific subfolder to the address with that custom 8081 port. The webcam streamer and octoprint are configured that way.

Example haproxy.cfg

        maxconn 4096
        user haproxy
        group haproxy
        log /dev/log local1 debug

        log     global
        mode    http
        compression algo gzip
        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 v4v6
        bind :::443 v4v6 ssl crt /etc/ssl/snakeoil.pem
        option forwardfor except
        use_backend webcam if { path_beg /webcam/ }
        use_backend family if { path_beg /family/ }
        default_backend octoprint

backend octoprint
        acl needs_scheme req.hdr_cnt(X-Scheme) eq 0

        reqrep ^([^\ :]*)\ /(.*) \1\ /\2
        reqadd X-Scheme:\ https if needs_scheme { ssl_fc }
        reqadd X-Scheme:\ http if needs_scheme !{ ssl_fc }
        option forwardfor
        server octoprint1
        errorfile 503 /etc/haproxy/errors/503-no-octoprint.http

backend webcam
        reqrep ^([^\ :]*)\ /webcam/(.*)     \1\ /\2
        server webcam1
        errorfile 503 /etc/haproxy/errors/503-no-webcam.http

backend family
        reqrep ^([^\ :]*)\ /family/(.*)     \1\ /\2
        server family1

Then when you go to octoprint's address appended with /family/ it will redirect it to apache.
http://octopi.local/family/ or https;//octopi.local/family/ or or

1 Like

OK, thank you, I'll take a look at that.

the modified octopi image which is used with the pandaPi shield host an additional website to edit and compile Marlin.

But i don't have found the Source so far...

I've been thinking about this some more, and technically you could create a single file web page, manually edited/updated and use the errorfile 503 directive in a fake backend that is configured for a non-existent server.

If you are trying to use port 80, make sure that you don't have eg HAProxy forwarding port 80 to OctoPrint; no two services can use the same port at the same time.

Personally, I might spin up a NodeJS website on the same Pi as OctoPrint (as I've done before) on port 3000, for example, the default port for an Express-generated app.

As suggested, NGINX is also easy enough to setup.