ZoneMinder / zoneminder

ZoneMinder is a free, open source Closed-circuit television software application developed for Linux which supports IP, USB and Analog cameras.
http://www.zoneminder.com/
GNU General Public License v2.0
5.17k stars 1.23k forks source link

Reverse proxy configuration with Traefik2 #3302

Open aronmgv opened 3 years ago

aronmgv commented 3 years ago

Hello,

I am having quite troubles with configuring reverse proxy for Zoenminder (v1.36.4).

I am using addPrefix to add /zm/ in background so user can directly access Zoneminder on its subdomain cam.example.com. This partially works - I am getting the web page, but some styles are missing and stream is not working. After some time I get redirected to cam.example.com/zm/index.php - which does not exist on subdomain context.. If I tries to load cam.example.com/index.php it succeeds.

Direct access:

image

vs

Subdomain access:

image

For the streams its the same scenario:

image

Traefik2 configuration for the reverse proxy zoneminder:

http:

  routers:
    zoneminder.example.com:
      priority: 1
      entryPoints:
        - websecure
      rule: Host(`cam.example.com`)
      service: zoneminder.example.com
      middlewares:
        - zoneminder.example.com+addPrefix
        #- zoneminder.example.com+replacePathRegex

  services:
    zoneminder.example.com:
      loadBalancer:
        passHostHeader: true
        servers:
          - url: 'http://192.168.255.12:50191'

  middlewares:
    zoneminder.example.com+addPrefix:
      addPrefix:
        prefix: /zm
    zoneminder.example.com+replacePathRegex:
      replacePathRegex:
        regex: "/zm/index(.+)"
        replacement: "/index$1"

Any directions will be appreciated. Thanks, Michal

welcome[bot] commented 3 years ago

Thanks for opening your first issue here! Just a reminder, this forum is for Bug Reports only. Be sure to follow the issue template!

zombielinux commented 3 years ago

I have been having the same problem for quite some time, but to a greater extent.

I have traefik2 set up properly (works with other services) and multiple ZM servers in a multi-server configuration on top of docker swarm. Live streams do not work because of some redirecting that is done to a host that is not accessible from outside the docker network. Likewise, the API access also fails.

I am inclined to believe at this point that unless you are running a single instance of ZM on non-swarm docker, you are unlikely to be successful.

aronmgv commented 3 years ago

@zombielinux actually this is my scenario. Just single instance on non-swarm docker.

Similar deployment has also the Guacamole project. Where you have apache server hosting the app on the prefix /guacamole. Here adding just addPrefix: /guacamole works 100%..

michael-robbins commented 3 years ago

So I tried this as well a while back and it never worked for me, instead I used a redirect to solve this, and it's been fine for me (users going to the parent page are nicely redirected automatically):

      traefik.http.routers.zoneminder.middlewares: "zoneminder-redir"
      traefik.http.middlewares.zoneminder-redir.redirectregex.regex: "^https:\\/\\/([^\\/]+)\\/?$"
      traefik.http.middlewares.zoneminder-redir.redirectregex.replacement: "https://$1/zm/"
aronmgv commented 3 years ago

@michael-robbins Tried it as well using different pattern and didnt work:

        regex: "^https?://cam.example.com/(.*)"
        replacement: "https://cam.example.com/zm/"

Yours works for me:

        regex: "^https?://([^/]+)/?$"
        replacement: "https://$1/zm/"

Mind explaining me this part: ([^/]+)/? please? Appreciate! Michal

EDIT: I think I get it now.. we strictly just match the FQDN - in other words anything between / sub3.sub2.sub1.dom.com / and this forcibly has applied /zm/ path segment.. Haven't yet seen such one.. Thanks again.

michael-robbins commented 3 years ago

Not gonna lie, I just copied it off another GitHub comment somewhere lol

But yes it's just another way to match the domain!

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.