API with nginx

Forum for questions and support relating to the 1.28.x releases only.
Locked
jhmiller
Posts: 8
Joined: Sat Mar 01, 2014 9:52 am

API with nginx

Post by jhmiller »

Trying to get the API working with nginx without any luck.

I can see x.x.x.x/zm/api/index.php but that just shows an error/warning
"URL rewriting is not properly configured on your server. 1) Help me configure it 2) I don't / can't use URL rewriting"

If I follow option 2 (I don't / can't use URL rewriting) and uncomment the suggested line I get all green boxes but /zm/api/host/getVersion.json does not work (404 Not Found)

This is my current nginx.conf

Code: Select all

location /zm {
   if ($scheme ~ ^http:){
       rewrite ^(.*)$  https://$host$1 permanent;
   }
   try_files $uri $uri/ /index.php?$args;
   gzip off;
   alias                   /usr/share/zoneminder;
   index                   index.php;


    location /zm/cgi-bin {
        gzip off;
        alias /usr/lib/zoneminder/cgi-bin;

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

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

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

    location /zm/api {
        alias                   /usr/share/zoneminder/api;
        #try_files   $uri  $uri/  @cakephp;
    }

}
Has anyone got the API working or even tried to get it working with nginx?

Thanks
Miller
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: API with nginx

Post by asker »

Never tried, but I found links that talk about CakePHP configuration for nginx. You may have already referred to them

http://www.scalescale.com/tips/nginx/ng ... framework/
http://book.cakephp.org/2.0/en/installa ... iting.html (refer to nginx part)

If you get it working, please let me know all the steps so I can add it to the API wiki.

thx
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
jhmiller
Posts: 8
Joined: Sat Mar 01, 2014 9:52 am

Re: API with nginx

Post by jhmiller »

After some playing around with the config I managed to call the current version via the API from

Code: Select all

http://192.168.123.66/zm/api/host/getVersion.json

Code: Select all

{
    "version": "1.28.109",
    "apiversion": "1.28.109.1"
}
I still get
"URL rewriting is not properly configured on your server. 1) Help me configure it 2) I don't / can't use URL rewriting"

Can I just ignore this if the API is functioning? are there some other commands to further test the API bearing in mind that I am currently running in a VM without any cameras attached.
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: API with nginx

Post by asker »

Do all the API's work - such as

http://192.168.123.66/zm/api/host/getVersion.json
http://192.168.123.66/zm/api/monitors.json
http://192.168.123.66/zm/api/events.json


If so, should be good. If you don't have cameras connected, create dummy cameras with source as file and test
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
jhmiller
Posts: 8
Joined: Sat Mar 01, 2014 9:52 am

Re: API with nginx

Post by jhmiller »

Yep they all work.

I installed this version on my production machine and used your desktop app to double check and everything looks to be working great.
I have been working on Zoneminder for the debian (wheezy) based OpenMediaVault NAS O/S and I suspect that the webui for the O/S is the cause of the URL rewriting issue. I will keep trying to resolve it though.

Cheeky request
Can I be allowed to now try the android version of your app ;)

Miller
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: API with nginx

Post by asker »

Sure - i've opened up Android - please see the zmninja post of the mobile forum thread for the download link
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: API with nginx

Post by asker »

Also would it be possible to post a list of everything you changed with nginx so I can point to it from my wiki?
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
jhmiller
Posts: 8
Joined: Sat Mar 01, 2014 9:52 am

Re: API with nginx

Post by jhmiller »

This is the conf that I am currently using

Code: Select all

location /zm/cgi-bin {
    gzip off;
    alias /usr/lib/cgi-bin;

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

location /zm {
    gzip off;
    alias                   /usr/share/zoneminder;
    index                   index.php;

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

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

    location /zm/api/ {
        alias                   /usr/share/zoneminder/api;
        rewrite ^/zm/api(.+)$ /zm/api/index.php?p=$1 last;
    }
}
I will try the android app now, thanks.

Miller
firsttris
Posts: 2
Joined: Wed Dec 09, 2015 8:36 am

Re: API with nginx

Post by firsttris »

Hello,

also trying to get api working in openmediavault

would be very nice if you could explain in a little more detail:

do i need to add this locations to /etc/nginx/sites-available/nginx.conf ?

my current nginx-conf => https://dl.dropboxusercontent.com/u/13344648/nginx.conf

regards
tristan
jhmiller
Posts: 8
Joined: Sat Mar 01, 2014 9:52 am

Re: API with nginx

Post by jhmiller »

Did you follow my guide to build ZM for OMV?

If so it has been updated to include the api. follow it again to build and updated package and it will upgrade your current 1.28 to 1.28.109. Don't change anything yourself as the upgrade may fail if you do.
firsttris
Posts: 2
Joined: Wed Dec 09, 2015 8:36 am

Re: API with nginx

Post by firsttris »

thx jhmiller, after recompiling with your guide - webcontext root is correct and api is working.
Locked