0

Hope someone can help me :)

I try to configure HAProxy for plex redirection but didn't found the solution yet. So basically to run plex home page you should go to => IPADRESS:PORT/web which redirect to IPADRESS:PORT/web/index.html

I made this kind of redirect:

use_backend plex if { hdr_beg(Host) -i plex. }

backend plex
    server plex localhost:32400 check

This is ok, i can join plex => plex.mydomain.tld/web

But i would like to be able to join plex with this URL => plex.mydomain.tld

I tried to add this line:

reqrep ^([^\ :]*)\ /(.*)     \1\ /web\2

Changing is fine, my URL switch to => plex.mydomain.tld/web/index.html

But i have a 404 ERROR...

What kind of trick i should do to acces plex from plex.mydomain.tld ?

Thanks !

ochbob
  • 1
  • 1
  • 2

3 Answers3

2

Found some info that helped me figure it out:

global
    log         127.0.0.1 syslog
    maxconn     1000
    user        haproxy
    group       haproxy
    daemon
    tune.ssl.default-dh-param 4096
    ssl-default-bind-options no-sslv3 no-tls-tickets
    ssl-default-bind-ciphers EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH


defaults
    log  global
    mode  http
    option  httplog
    option  dontlognull
    option  http-server-close
    option  forwardfor except 127.0.0.0/8
    option  redispatch
    option  contstats
    retries  3
    timeout  http-request 10s
    timeout  queue 1m
    timeout  connect 10s
    timeout  client 1m
    timeout  server 1m
    timeout  check 10s

listen stats
    bind *:9090
    mode  http
    maxconn  10
    stats  enable
    stats  hide-version
    stats  realm Haproxy\ Statistics
    stats  uri /
    stats  auth admin:admin

frontend ALL
    bind   *:80
    bind   *:443 ssl crt /etc/haproxy/certs/nomercy.myqnapcloud.com.pem crt /etc/haproxy/certs/nomercy.myqnapcloud.com.pem
    mode   http

    # Define path for lets encrypt
    acl is_letsencrypt path_beg -i /.well-known/acme-challenge/
    use_backend letsencrypt if is_letsencrypt

    # Define hosts
    acl host_website hdr(host) -i nomercy.myqnapcloud.com

    # Direct hosts to backend
    use_backend website if host_website

    # Redirect port 80 to 443
    # But do not redirect letsencrypt since it checks port 80 and not 443
    redirect scheme https code 301 if !{ ssl_fc } !is_letsencrypt

backend letsencrypt
    server letsencrypt 127.0.0.1:8888

backend website
    balance         roundrobin
    option          httpchk GET /check
    cookie          SERVERID insert indirect nocache
    http-check      expect rstring ^UP$
    default-server  inter 3s fall 3 rise 2
    server          server1 192.168.2.151:8888 check
    server          server2 192.168.2.152:8888 check
    server          server3 192.168.2.153:8888 check


listen plex
    bind *:32400 ssl crt /etc/haproxy/certs/nomercy.myqnapcloud.com.pem crt /etc/haproxy/certs/nomercy.myqnapcloud.com.pem
    balance         roundrobin
    option          httpchk GET /check
    http-check      expect rstring ^UP$
    default-server  inter 3s fall 3 rise 2
    server          server1 192.168.2.149:32400 check port 8888
    server          server2 192.168.2.148:32400 check port 8888
    server          server3 192.168.2.147:32400 check port 8888

You can remove the ssl credentials if you don't have it installed.

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
Stoney Eagle
  • 982
  • 8
  • 11
1

The problem here unfortunately has nothing to do with your HAProxy configuration. Instead it is Plex that is causing the issue.

Example

With your configuration, when you go to plex.mydomain.tld HAProxy is adding in the /web and as a result Plex gets the following url: plex.mydomain.tld/web. This is correct however Plex will then want to forward the browser on to plex.mydomain.tld/web/index.html. But when the browser sends a request or that url, HAProxy steps in and adds that extra /web again and the resulting url that is set to Plex is plex.mydomain.tld/web/web/index.html which doesn't exist and hence the 404 error you got.

While going to plex.mydomain.tld/index.html may work, I assume all links from that page to any other page won't work due to the say issue.

To solve this you could

  1. Look through Plex's configuration to see if it is possible to run it with out the /web.
  2. Taking inspiration from here, you could configure HAProxy something like this:

    frontend http
        mode http
        bind *:80
    
        acl plex hdr_beg(Host) -i plex.
        acl root_dir path_reg ^$|^/$
        acl no_plex_header req.hdr_cnt(X-Plex-Device-Name) -i 0
    
        redirect location http://plex.mydomain.tld/web/index.html 301 if no_plex_header root_dir plex
        use_backend plex if plex
    
    backend plex
        server plex localhost:32400 check
    

    The key difference being the redirect location line which will redirect from / to /web/index.html if the header X-Plex-Device-Name isn't set. The reason you have to check for the header is that it appears that plex uses / for something else.

    Note: This config is an example and I haven't tested this at all

Hope that helps.

JamesStewy
  • 1,058
  • 15
  • 26
0

I want to echo that I used the solution provided by JamesStewy and it worked, with the minor correction;

redirect location http://plex.mydomain.tld/web/index.html code 301 if no_plex_header root_dir plex

At least, that was necessary for me (running haproxy 1.7.2).