OctoPrint + website running on Apache2


#1

Hello everyone!

I'm trying to set up OctoPrint together with apache2 web server on my Raspberry Pi 3. I've already tried to set up everything in haproxy, but I just don't know how to set it up properly. **I know, that it may not be a good idea, but I still want to try that out :smiley: **

I would like to set up everythig to work like that:

domain.com >> apache2 virtual host domain.com
sub.domain.com >> apache2 virtual host sub.domain.com
3d.domain.com >> OctoPrint

Below is my current haproxy config file. I was somehow able to correctly set up https redirect with Let's Encrypt certificate (took me a night, but works).

global
        maxconn 512
        user haproxy
        group haproxy
        log 127.0.0.1 local1 debug
        tune.ssl.default-dh-param 2048

defaults
    option forwardfor
    option http-server-close
        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
    errorfile 400 /etc/haproxy/errors/400.http
    errorfile 403 /etc/haproxy/errors/403.http
    errorfile 408 /etc/haproxy/errors/408.http
    errorfile 500 /etc/haproxy/errors/500.http
    errorfile 502 /etc/haproxy/errors/502.http
    errorfile 503 /etc/haproxy/errors/503.http
    errorfile 504 /etc/haproxy/errors/504.http

frontend public
        bind *:80
    reqadd X-Forwarded-Proto:\ http
    default_backend octoprint
        option forwardfor except 127.0.0.1
        use_backend webcam if { path_beg /webcam/ }
        default_backend octoprint

frontend www-https
    bind *:443 ssl crt /etc/haproxy/certs/cert.pem
    reqadd X-Forwarded-Proto:\ https
    http-request set-header X-SSL %[ssl_fc]
    acl letsencrypt-acl path_beg /.well-known/acme-challenge/
    use_backend letsencrypt-backend if letsencrypt-acl
    default_backend octoprint

backend octoprint
        server octoprint1 127.0.0.1:5000
        redirect scheme https code 301 if !{ ssl_fc }

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

backend letsencrypt-backend
   server letsencrypt 127.0.0.1:54321