Jump to content

REST API - For nginx?


Recommended Posts

I just added:

location /forums/api {
	try_files	$uri $uri/ /forums/api/index.php;
}

 

Now it just seems the API is broken, the key is correctly passed to the script (even checked by echoing the $rawApiKey variable), it just throws an exception:

curl http://localhost/forums/api/core/hello --user test: 
{                                                                                                                     
    "errorCode": "3S290\/7",                                                                                          
    "errorMessage": "INVALID_API_KEY"                                                                                 
}    

curl http://localhost/forums/api/core/hello              
{                                                                                                                     
    "errorCode": "2S290\/6",                                                                                          
    "errorMessage": "NO_API_KEY"                                                                                      
}                                                                                                                     

 

Edited by Sly_Ripper
Link to comment
Share on other sites

7 hours ago, prupdated said:

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

Seems to be working (adjust for your directory structure as needed).

I used the sample script here:

 

Which outputs as expected (replaced name and url):


php testapi.php 
{
    "communityName": "name",
    "communityUrl": "url",
    "ipsVersion": "4.1.6"
}

 

Strange, I'm still getting "INVALID_API_KEY".

Link to comment
Share on other sites

15 hours ago, Sly_Ripper said:

I just added:


location /forums/api {
	try_files	$uri $uri/ /forums/api/index.php;
}

 

Now it just seems the API is broken, the key is correctly passed to the script (even checked by echoing the $rawApiKey variable), it just throws an exception:


curl http://localhost/forums/api/core/hello --user test: 
{                                                                                                                     
    "errorCode": "3S290\/7",                                                                                          
    "errorMessage": "INVALID_API_KEY"                                                                                 
}    

curl http://localhost/forums/api/core/hello              
{                                                                                                                     
    "errorCode": "2S290\/6",                                                                                          
    "errorMessage": "NO_API_KEY"                                                                                      
}                                                                                                                     

I have the same nginx rule and it is working fine for me. You need to use

curl --user APIKEY http://domain.com/api/core/hello
Link to comment
Share on other sites

Just now, Sly_Ripper said:

Still the same result, I don't have any proper API Keys yet since the admin panel doesn't let you add any until it works with the "test" key.

After adding the nginx rule and restarting nginx, just reload the REST API page in the ACP, it should go through automatically and let you add an key.

Link to comment
Share on other sites

4 hours ago, Ahmad E. said:

Are you using nginx only or are you using nginx as a proxy for apache? Never used plesk myself so not sure.

Nginx and php-fpm, tested it in Apache and it worked.

Edit:
I created an API key while using Apache, switched over to Nginx and using that key gives a valid result, but still using "test" as the key fails (and so the AdminCP shows no options to add/edit keys yet).

>curl http://localhost/forums/api/core/hello --user a33cb937a4953c72bc4da6e89da39e51:
{                                                                                                                                                
    "communityName": "IPS Community Suite",                                                                                                      
    "communityUrl": "http:\/\/localhost\/forums\/",                                                                                             
    "ipsVersion": "4.1.6"                                                                                                                        
}                                                                                                                                                
>curl http://localhost/forums/api/core/hello --user test:                            
{                                                                                                                                                
    "errorCode": "3S290\/7",                                                                                                                     
    "errorMessage": "INVALID_API_KEY"                                                                                                            
}                                                                                                                                                

@bfarber Should I submit a bug report?

Edited by Sly_Ripper
Link to comment
Share on other sites

19 minutes ago, Sly_Ripper said:

Nginx and php-fpm, tested it in Apache and it worked.

Edit:
I created an API key while using Apache, switched over to Nginx and using that key gives a valid result, but still using "test" as the key fails (and so the AdminCP shows no options to add/edit keys yet). Should I submit a bug report?

Not sure if it's a bug as it worked fine for me on my nginx install, I'll test it on my other site which also runs nginx.

Update: Works fine as-well.

Edited by Ahmad E.
Link to comment
Share on other sites

42 minutes ago, Jimmy Gavekort said:

Hmm i think it's weird how they are not providing any support or guides regarding nginx.. apache is way too slow, nginx should be one of the default configs supported

Post it in the feedback section. Most developers don't support nginx, unfortunately. But I never had a problem getting things to work myself with nginx.

Edited by Ahmad E.
Link to comment
Share on other sites

Yeah I'm surprised they haven't added NGINX support. I bet a large chunk of their customers use NGINX yet they're still stuck on Apache for some odd reason. @Ahmad E. the issue really isn't getting things to work with NGINX as anyone that is semi-competent can make it happen. The problem is when you open a support ticket with Invision Power and they use the fact that you have NGINX as a reason not to provide you with proper support. I had issues before where the imageproxy key needed a new hash because I changed my subdomain URL around and when I opened a ticket (this is before I knew about the hashgenerator.php), they shot me down because they claimed they don't support PHP 7 or NGINX. Yet my issue had nothing to do with either of those and I was left to figure it out on my own.

Edited by Brian K.
Link to comment
Share on other sites

  • 2 weeks later...
On 2016-01-07 at 10:11 PM, JEFF MACK said:

So not sure what I am doing wrong.  I downloaded the file, etc but yet this doesn't seem to work...

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

You don't need the file when using NGINX.

I'm experiencing the same problem when on my test install. On my production server it works as expected and I'm pretty much using the same config except that the test install uses a auth_basic on the whole site... (this could be the issue!)

The following is the path that IPS is trying to access according to the NGINX logs. The post here says that it is invalid https://community.invisionpower.com/4guides/developing-plugins-and-applications/rest-api/sending-your-first-request-r167/

/api/index.php?/core/hello

The config I use is the one that @prupdated mentioned above, IE

location /api/ {
  rewrite ^/api/(.*)$ /api/index.php;
}
Link to comment
Share on other sites

10 minutes ago, emilhem said:

You don't need the file when using NGINX.

I'm experiencing the same problem when on my test install. On my production server it works as expected and I'm pretty much using the same config except that the test install uses a auth_basic on the whole site... (this could be the issue!)

The following is the path that IPS is trying to access according to the NGINX logs. The post here says that it is invalid https://community.invisionpower.com/4guides/developing-plugins-and-applications/rest-api/sending-your-first-request-r167/


/api/index.php?/core/hello

The config I use is the one that @prupdated mentioned above, IE


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

And that works?

Link to comment
Share on other sites

  • 5 years later...
On 1/20/2016 at 12:36 PM, emilhem said:

You don't need the file when using NGINX.

I'm experiencing the same problem when on my test install. On my production server it works as expected and I'm pretty much using the same config except that the test install uses a auth_basic on the whole site... (this could be the issue!)

The following is the path that IPS is trying to access according to the NGINX logs. The post here says that it is invalid https://community.invisionpower.com/4guides/developing-plugins-and-applications/rest-api/sending-your-first-request-r167/

/api/index.php?/core/hello

The config I use is the one that @prupdated mentioned above, IE

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

For me I had to do:

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

 

Thank you for the solution !

Link to comment
Share on other sites

  • 1 month later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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