# Api-tools reverse proxying

**URL:** <https://discourse.laminas.dev/t/api-tools-reverse-proxying/2326>\
**Category:** API Tools\
**Created:** [May 31, 2021, 2:57pm UTC](https://discourse.laminas.dev/t/api-tools-reverse-proxying/2326 "2021-05-31T14:57:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![phandaal](https://avatars.discourse-cdn.com/v4/letter/p/958977/32.png) [@phandaal](https://discourse.laminas.dev/u/phandaal)\
**Post date:** [May 31, 2021, 2:57pm UTC](https://discourse.laminas.dev/t/api-tools-reverse-proxying/2326/1 "2021-05-31T14:57:42Z")

</div>

I have to make my API available through an nginx reverse proxy with a URL in the form of :  
https://proxy\_server/api/, where proxy\_server is a proxy only nginx server and the api tools are installed on a second server (api\_server).

- I installed laminas api-tools on the api\_server through the recommended method : composer create-project laminas-api-tools/api-tools-skeleton path/to/install on the api\_server
- direct connection to the api tools through http://api\_server:8080 works (with the php -S method and also with the local nginx on api\_server).

But I cannot get the connection to work through the proxy.

On the proxy\_server nginx, I have tested two methods of proxying :

1. not stripping the /api/ part of the URL :  
location /api/ {  
proxy\_pass [http://reac-saisie-dev:8091/api/](http://reac-saisie-dev:8091/api/);  
}

with, on the api\_server :  
location /api/ {  
try\_files $uri $uri/ /index.php?$query\_string;  
}

Result :

## Page not found.

The requested URL could not be matched by routing.

index.php in the path/to/install/api/dev/ is executed, but it does not understand what to do.

1. stripping the /api/ part of the URL on the proxy\_server  
location /api/ {  
proxy\_pass [http://reac-saisie-dev:8091/](http://reac-saisie-dev:8091/);  
}

with, on the api\_server :  
location / {  
try\_files $uri $uri/ /index.php?$query\_string;  
}

Result :  
index.php is executed, but redirects to  
https://proxy\_server/api-tools/ui  
which of course, does not work (404 error)

I imagine that I should continue with solution 2 (stripping the /api/ part of the URL on the proxy\_server, but the api\_server (the laminas api tools) need to add that part (/api/) in all its generated URLs (redirections, URLs on pages…).

How do I do that ?

Thanks a lot for helping.
