Jump to content

REST API setting up for nginx


Recommended Posts

Posted

Hello all!

While trying to take API key in REST API section we got warning that we need to create .htaccess file in /api derrictory. And there is also code that we need to use for it:

Quote

<IfModule mod_setenvif.c>
SetEnvIf Authorization .+ HTTP_AUTHORIZATION=$0
</IfModule>
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /casinoforum/api/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
</IfModule>

...this is correct for servers with Apache.

But what to do if we have no Apache?

No working solutions were googled. 2-3 were but they faild to run...

Please, сolleagues, any ideas how to solve this?...

Posted
3 hours ago, Liyu said:

Hello all!

While trying to take API key in REST API section we got warning that we need to create .htaccess file in /api derrictory. And there is also code that we need to use for it:

...this is correct for servers with Apache.

But what to do if we have no Apache?

No working solutions were googled. 2-3 were but they faild to run...

Please, сolleagues, any ideas how to solve this?...

I just added this to my nginx default.conf

	location /api/ {
        rewrite ^/api/(.*)$ /api/index.php;

You can read more on it here:

 

Posted

I don't know if this will help, but..... these are the lines I added to my install which uses nginx (it's openmediavault as a base, with their nginx plugin).
This is the partial contents of the relevant nginx config file, and includes the REST API rewrite.
it works on my install, and allows REST API use without errors.
************************************************************************

location / {
    index index.html index.php;
    try_files $uri $uri/ /index.php?$args;
}
location /api/ {
    index index.html index.php;
    try_files $uri $uri/ /api/index.php?$args;
}

Posted

First of all, here is the best way I've been able to find to setup IPB4 with nginx. 

https://invisioncommunity.com/forums/topic/424510-setting-up-a-secure-nginxphp-fpm-installation-for-ips4

This uses PHP-FPM so it's blazing fast.  Be sure to follow his recommendations for security.

Now, to add API support to the above recipe, add the following stanzas:

    location ~ ^/api/ {
        try_files $uri @ipsapi;
        include         /etc/nginx/includes/php_fastcgi_params;
        fastcgi_pass    php_backend;
    }

   location @ipsapi {
        root                  /your/forum/root_directory/api;
        include             /etc/nginx/includes/php_fastcgi_params;
        fastcgi_pass        php_backend;

        fastcgi_param       SCRIPT_FILENAME  $document_root/index.php;
        fastcgi_param       SCRIPT_NAME      /index.php;
    }

I'm no nginx expert, so the above can probably be improved, but it works for me.

Cheers,

Hermann

 

  • 3 weeks later...
  • 7 months later...
Posted

Does anyone has problem with "AdminCP -> REST API" page?
I use this example:

and REST API is work. So now "http://localhost/api/core/hello" respond next:

{
    "errorCode": "2S290\/6",
    "errorMessage": "NO_API_KEY"
}

But in AdminCP page says:

Quote

The API endpoint is not giving the expected response. Check you followed the instructions correctly. The URL being tested is: http://localhost/api/core/hello

So I cannot generate API key at all :( Any help?

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...