reverse proxy broken on /cgi/bin/

Forum for questions and support relating to the 1.32.x releases only.
Post Reply
cTurtle98
Posts: 16
Joined: Sun Nov 13, 2016 3:18 am
Location: Santa Cruz, CA, USA
Contact:

reverse proxy broken on /cgi/bin/

Post by cTurtle98 »

my zoneminder 1.32.2 is running behind an apache reverse proxy
heres the apache virtualhost config

Code: Select all

	ServerName www.cturtle98.com
	ServerAlias cturtle98.com
	
	ProxyPass "/zm" "http://localhost:8005/zm"
	ProxyPassReverse "/zm" "http://localhost:8005/zm"
but its not showing the streams
they are just showing up with the broken image icon

if I right click on the broken image icon and copy the URL its this
http://localhost:8005/zm/cgi-bin/nph-zm ... 1544146912

it seems zoneminder doesn't know its behind the proxy and instead of serving the images on a relative domain its serving it on a static domain of however you accessed the server and since the apache proxy is trying to get the server at localhost it tries to serve the image at localhost

do I need to do something in the reverse proxy config to make this work or can I change a setting on zoneminder for the base url?
how can I fix this?
tribouth
Posts: 1
Joined: Sun Dec 30, 2018 10:11 pm

Re: reverse proxy broken on /cgi/bin/

Post by tribouth »

Hi,

I have exactly the same issue.
In you apache conf try to add "ProxyPreserveHost On". It solve partially the issue for me. Hostname is now used.
But the protocol (https) is still missing, so I still can't show the stream.

Regards
rockedge
Posts: 1166
Joined: Fri Apr 04, 2014 1:46 pm
Location: Connecticut,USA
Contact:

Re: reverse proxy broken on /cgi/bin/

Post by rockedge »

don't use localhost....use the subnet IP number like 192.168.0.12 or similar in the Apache configuration.
I run ZM servers behind reverse proxy using Apache or Hiawatha which successfully stream camera feeds.

here is an example of what works for me ->

Code: Select all

<VirtualHost *:80>
	ServerName gate.alias.org
#	ServerAlias gate.alias.org
	
	ServerAdmin techdirector@localhost
   	ProxyRequests off
    DocumentRoot /var/www
    SSLProxyEngine on
   ProxyPreserveHost On
   ProxyPass /  http://192.168.0.13:80/
   ProxyPassReverse / http://192.168.0.13:80/

	ErrorLog ${APACHE_LOG_DIR}/error.log

	# Possible values include: debug, info, notice, warn, error, crit,
	# alert, emerg.
	LogLevel warn

	CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
robbyrob
Posts: 1
Joined: Thu Jan 24, 2019 8:58 pm

Re: reverse proxy broken on /cgi/bin/

Post by robbyrob »

I got it working with and without Apache Proxy with the following two steps:

Apache proxy config:

Code: Select all

ProxyPass /zm http://<ip of zm server>/zm
ProxyPassReverse /zm http://<ip of zm server>/zm
ProxyPass /cgi-bin http://<ip of zm server>/cgi-bin
ProxyPassReverse /cgi-bin http://<ip of zm server>/cgi-bin
ProxyPreserveHost On
RequestHeader set X-Forwarded-Proto "https"
RequestHeader set X-Forwarded-Port "443"
SSLEngine on
SSLCertificateFile <path to your cert>.pem
SSLCertificateKeyFile <path to your privkey>.pem
</VirtualHost>
ZoneMinder 1.32.3 needs a little code modification in the "public function Protocol" and "public function Port" in
/usr/share/zoneminder/www/includes/Server.php:

Code: Select all

  public function Protocol( $new = null ) {
    if ( $new != null )
      $this->{'Protocol'} = $new;

    if (!empty($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
        return $_SERVER['HTTP_X_FORWARDED_PROTO'];
    }

    if ( isset($this->{'Protocol'}) and ( $this->{'Protocol'} != '' ) ) {
      return $this->{'Protocol'};
    }
    return (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? 'https' : 'http';
  }

  public function Port( $new = '' ) {
    if ( $new != '' )
      $this->{'Port'} = $new;

    if (!empty($_SERVER['HTTP_X_FORWARDED_PORT'])) {
      return $_SERVER['HTTP_X_FORWARDED_PORT'];
    }

    if ( isset($this->{'Port'}) and $this->{'Port'} ) {
      return $this->{'Port'};
    }
    return $_SERVER['SERVER_PORT'];
  }
I hope this will help others to get it run.
Cheers :D
cTurtle98
Posts: 16
Joined: Sun Nov 13, 2016 3:18 am
Location: Santa Cruz, CA, USA
Contact:

Re: reverse proxy broken on /cgi/bin/

Post by cTurtle98 »

I am using this docker image that is pre-setup for my UnRaid OS for Zoneminder so I cant do what you said modifying the zoenminder server unless I want to do a deep dive in how this person setup the docker and fork it
https://hub.docker.com/r/dlandon/zoneminder

my apache proxy server is however a docker I setup myself
https://hub.docker.com/r/cturtle98/apache-proxy
Post Reply