Page 1 of 1

api and nginx

Posted: Tue Nov 13, 2018 10:00 pm
by abi
Hello, can you give me tip how to setup api with nginx ?

Code: Select all

Warning (2): require_once(../../../includes/config.php): failed to open stream: No such file or directory [APP/Config/bootstrap.php, line 123]


Fatal error: require_once() [function.require]: Failed opening required '../../../includes/config.php' (include_path='.:/usr/local/share/pear') in /usr/local/www/zoneminder/api/app/Config/bootstrap.php on line 123

Notice (8): Use of undefined constant ZM_OPT_USE_API - assumed 'ZM_OPT_USE_API' [APP/Controller/AppController.php, line 63]

Notice (8): Use of undefined constant ZM_OPT_USE_AUTH - assumed 'ZM_OPT_USE_AUTH' [APP/Controller/AppController.php, line 72]

Warning (2): require_once(../../../includes/auth.php) [<a href='http://php.net/function.require-once'>function.require-once</a>]: failed to open stream: No such file or directory [APP/Controller/AppController.php, line 73]


Fatal error: require_once() [function.require]: Failed opening required '../../../includes/auth.php' (include_path='.:/usr/local/share/pear') in /usr/local/www/zoneminder/api/app/Controller/AppController.php on line 73
I use example from this distro https://github.com/ZoneMinder/zoneminde ... onf.in#L50
This looks impossible - getcwd() is /usr/local/www/zoneminder/api with this rewrite, so ../../../ is obviously wrong.

Full config (ZM web interface is fully operational with this one, only api throws errors):

Code: Select all

server {

    listen 80;

    location /cgi-bin/nph-zms {
        gzip off;
        root /usr/local/www/zoneminder;

        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $request_filename;
        fastcgi_pass  unix:/var/run/fcgiwrap/fcgiwrap.sock;
    }


    location /zm/cache {
        alias /var/cache/zoneminder;
    }
    
    location /zm {
        gzip off;
        alias                   /usr/local/www/zoneminder;
        index                   index.php;

        location ~ \.php$ {
            if (!-f $request_filename) { return 404; }
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $request_filename;
            fastcgi_index index.php;
            fastcgi_pass unix:/var/run/php-fpm.sock;
        }

        location ~ \.(jpg|jpeg|gif|png|ico)$ {
            access_log          off;
            expires         33d;
        }


        location /zm/api/ {
            alias                   /usr/local/www/zoneminder;
            rewrite ^/zm/api(.+)$ /zm/api/index.php?p=$1 last;
        }
    }
}

Re: api and nginx

Posted: Tue Nov 13, 2018 10:10 pm
by abi
Maybe, I should rewrite to api/app/webroot/index.php ?

Re: api and nginx

Posted: Wed Nov 14, 2018 3:31 pm
by Nocifer
Yes, this specific error can be fixed by rewriting to 'api/app/webroot' instead of just 'api'.

Re: api and nginx

Posted: Sun Nov 18, 2018 8:47 am
by Pedulla
@api
Full config (ZM web interface is fully operational with this one, only api throws errors):
Do you mind sharing how you got ZM to work on ngnix?

I've yet to figure this one out.

Re: api and nginx

Posted: Sun Nov 18, 2018 6:35 pm
by knight-of-ni
I just finished splitting the official zoneminder rpm into apache and nginx subpackages. I was testing the nginx portion for the first time when I noticed the api support in the nginx config was broken. I knew there was some existing conversation in the user forum so I went looking for a quick fix.

Sure enough, changing the rewrite fixed the issue. Thank you.

The nginx config for redhat lives here now:
https://github.com/ZoneMinder/zoneminde ... nx.conf.in

I had to move several config files around and rename them slightly in order to make the rpm subpackages build.

Re: api and nginx

Posted: Sun Nov 18, 2018 10:20 pm
by abi
Pedulla wrote:
Sun Nov 18, 2018 8:47 am
@api
Full config (ZM web interface is fully operational with this one, only api throws errors):
Do you mind sharing how you got ZM to work on ngnix?

I've yet to figure this one out.
Here is nginx config for backend. ZMNinja works with this config. There are no gotchas at all, probably the only one is fcgiwrap children number (default value is 1).

Code: Select all

server {
    listen 80;

    root /usr/local/www/zoneminder;
    index index.php;
    gzip off;

    location / {
    
        return 301 /zm;
    }

    location /cgi-bin/nph-zms {

        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $request_filename;
        fastcgi_pass  unix:/var/run/fcgiwrap/fcgiwrap.sock;
    }

    location /zm/cache {

        alias /var/cache/zoneminder;
    }

    location /zm {

        alias   /usr/local/www/zoneminder;

        location ~ \.php$ {

            if (!-f $request_filename) { return 404; }
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $request_filename;
            fastcgi_index index.php;
            fastcgi_pass unix:/var/run/php-fpm.sock;
        }

        location ~ \.(jpg|jpeg|gif|png|ico)$ {
            access_log  off;
            expires     33d;
        }

        location /zm/api/ {
            alias       /usr/local/www/zoneminder;
            rewrite ^/zm/api(.+)$ /zm/api/app/webroot/index.php?p=$1 last;
        }

    }
}
I have a reverse proxy, that strips https, but it's pretty straightforward.

Re: api and nginx

Posted: Mon Nov 19, 2018 12:57 am
by Pedulla
Not to be dense, but I'll be dense...

Is this the entirety of the /etc/nginix/nginx.conf or is this an include conf in the .../sites-enabled/ ?

Re: api and nginx

Posted: Mon Nov 19, 2018 6:45 am
by abi
Pedulla wrote:
Mon Nov 19, 2018 12:57 am
Not to be dense, but I'll be dense...

Is this the entirety of the /etc/nginix/nginx.conf or is this an include conf in the .../sites-enabled/ ?
Include it was.
Here is my nginx.conf

Code: Select all

user  www;
worker_processes  1;

error_log  /var/log/nginx/error-default.log;

pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    server_tokens off;

    include /usr/local/etc/nginx/sites/*;
}
You may remove all ssl and gzip stuff though.