ZM 1.30.4 dowsn't work properly with nginx, but works with Apache2

Forum for questions and support relating to the 1.30.x releases only.
Locked
Maschinistin
Posts: 3
Joined: Wed Apr 11, 2018 10:48 am

ZM 1.30.4 dowsn't work properly with nginx, but works with Apache2

Post by Maschinistin »

Hello everyone.
When I've tried to use nginx on my zm server with such config

Code: Select all

server {
	listen 80;
	server_name blabla.com;
	rewrite ^ https://blabla.com$request_uri? permanent;
}

server {
	listen 443;
        server_name blabla.com;
	
	access_log  /var/log/nginx/access.log;
	error_log   /var/log/nginx/error.log info;

	expires 31d;

	ssl on;

	ssl_certificate     /etc/ssl/certs/server.crt;
	ssl_certificate_key /etc/ssl/certs/server.key;

        root /usr/share/zoneminder/www/;
        index index.php;
	location /cgi-bin {
	   gzip off;
	   root /usr/lib;
	 
	   include fastcgi_params;
	   fastcgi_param SCRIPT_FILENAME /usr/lib/zoneminder/cgi-bin/nph-zms;
	 
	   fastcgi_intercept_errors on;
	   fastcgi_pass unix:/var/run/fcgiwrap.socket;
	}
 
	 
	location ~ \.php$ {
	      include fastcgi_params;
	      # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
	      fastcgi_param SCRIPT_FILENAME $request_filename;
	      fastcgi_intercept_errors on;
	      fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
	   }
	 
	   location ~* /.*\.(txt|log)$ {
	      deny all;
	   }
	 
	   location ~* /.*\.(m4a|mp4|mov)$ {
	      mp4;
	      mp4_buffer_size 5M;
	      mp4_max_buffer_size 10M;
	   }
	
}
I've got this error in nginx logs? when I've tried to to watch video on camera:

Code: Select all

2018/04/11 15:23:46 [error] 19124#19124: *11392 open() "/usr/share/zoneminder/www/zm/cgi-bin/nph-zms" failed (2: No such file or directory), client: 88.212.194.51, server: video-server.hosting.reg.ru, request: "GET /zm/cgi-bin/nph-zms?mode=jpeg&scale=100&maxfps=5&buffer=1000&monitor=1&connkey=330229&rand=306881 HTTP/1.1", host: "blabla.com", referrer: "https://blabla.com/index.php?view=watch&mid=1"
with apache2 everything's fine

Code: Select all

<VirtualHost *:80>
        ServerName blabla.com
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        RewriteEngine On
        RewriteCond %{HTTPS} off
        RewriteRule (.*) https://%{SERVER_NAME}/$1 [R,L]
</VirtualHost>

<VirtualHost *:443>
    ServerName blabla.com
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    SSLCertificateFile /etc/ssl/certs/server.crt
    SSLCertificateKeyFile /etc/ssl/certs/server.key
</VirtualHost>
Any suggestions?
rockedge
Posts: 1173
Joined: Fri Apr 04, 2014 1:46 pm
Location: Connecticut,USA

Re: ZM 1.30.4 dowsn't work properly with nginx, but works with Apache2

Post by rockedge »

the configuration establishing the location of the /cgi-bin is not present. You must declare an alias and or the rewrite rules are causing the /cgi-bin not to be found. The programs that display the streams are there.
Maschinistin
Posts: 3
Joined: Wed Apr 11, 2018 10:48 am

Re: ZM 1.30.4 dowsn't work properly with nginx, but works with Apache2

Post by Maschinistin »

I've tried this official nginx config (changed php-fpm version) https://github.com/ZoneMinder/zoneminde ... nginx.conf, now zm shows stream video, but does'n play records. Here's error log:

Code: Select all

2018/04/12 13:45:22 [info] 3829#3829: *3 epoll_wait() reported that client prematurely closed connection, so upstream connection is closed too while sending request to upstream, client: 88.212.194.51, server: blabla.com, request: "GET /zm/cgi-bin/nph-zms?source=event&mode=jpeg&event=11&frame=1&scale=100&rate=100&maxfps=5&replay=single&connkey=846233&rand=1523529865 HTTP/1.1", upstream: "fastcgi://unix:/var/run/fcgiwrap.socket:", host: "blabla.com", referrer: "https://blabla.com/zm/?view=event&eid=11&trms=1&attr1=MonitorId&op1=%3d&val1=1&page=1"
2018/04/12 13:45:29 [error] 3829#3829: *5 FastCGI sent in stderr: "PHP message: ERR [Socket /var/run/zm/zms-756758s.sock does not exist.  This file is created by zms, and since it does not exist, either zms did not run, or zms exited early.  Please check your zms logs and ensure that CGI is enabled in apache and check that the PATH_ZMS is set correctly.  Make sure that ZM is actually recording.  If you are trying to view a live stream and the capture process (zmc) is not running then zms will exit. Please go to http://zoneminder.readthedocs.io/en/latest/faq.html#why-can-t-i-see-streamed-images-when-i-can-see-stills-in-the-zone-window-etc for more information.]" while reading response header from upstream, client: 88.212.194.51, server: blabla.com, request: "POST /zm/index.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.1-fpm.sock:", host: "video-server.hosting.reg.ru", referrer: "https://blabla.com/zm/?view=event&eid=2&trms=1&attr1=MonitorId&op1=%3d&val1=1&page=1"
Solution from http://zoneminder.readthedocs.io/en/lat ... window-etc doesn't help me, ZM_PATH_ZMS = /zm/cgi-bin/nph-zms
bbunge
Posts: 2934
Joined: Mon Mar 26, 2012 11:40 am
Location: Pennsylvania

Re: ZM 1.30.4 dowsn't work properly with nginx, but works with Apache2

Post by bbunge »

There is a how to in the WIKI for Ubuntu 16.04 and the soon to be released 18.04 for NGINX:
https://wiki.zoneminder.com/Ubuntu_Serv ... .2C_PHP.29
Maschinistin
Posts: 3
Joined: Wed Apr 11, 2018 10:48 am

Re: ZM 1.30.4 dowsn't work properly with nginx, but works with Apache2

Post by Maschinistin »

Thank's a lot, this solution helped me.
Locked