api and nginx

Forum for questions and support relating to the 1.32.x releases only.
Post Reply
abi
Posts: 59
Joined: Fri Oct 23, 2015 11:25 am

api and nginx

Post by abi » Tue Nov 13, 2018 10:00 pm

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;
        }
    }
}

abi
Posts: 59
Joined: Fri Oct 23, 2015 11:25 am

Re: api and nginx

Post by abi » Tue Nov 13, 2018 10:10 pm

Maybe, I should rewrite to api/app/webroot/index.php ?

Nocifer
Posts: 37
Joined: Mon Oct 01, 2018 4:05 pm

Re: api and nginx

Post by Nocifer » Wed Nov 14, 2018 3:31 pm

Yes, this specific error can be fixed by rewriting to 'api/app/webroot' instead of just 'api'.

Pedulla
Posts: 133
Joined: Thu Nov 27, 2014 11:16 am
Location: Portland, Or

Re: api and nginx

Post by Pedulla » 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.

User avatar
knight-of-ni
Posts: 2231
Joined: Thu Oct 18, 2007 1:55 pm
Location: Shiloh, IL

Re: api and nginx

Post by knight-of-ni » Sun Nov 18, 2018 6:35 pm

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.
Visit my blog for ZoneMinder related projects using the Raspberry Pi, Orange Pi, Odroid, and the ESP8266
All of these can be found at https://zoneminder.blogspot.com/

abi
Posts: 59
Joined: Fri Oct 23, 2015 11:25 am

Re: api and nginx

Post by abi » Sun Nov 18, 2018 10:20 pm

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.

Pedulla
Posts: 133
Joined: Thu Nov 27, 2014 11:16 am
Location: Portland, Or

Re: api and nginx

Post by Pedulla » 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/ ?

abi
Posts: 59
Joined: Fri Oct 23, 2015 11:25 am

Re: api and nginx

Post by abi » Mon Nov 19, 2018 6:45 am

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests