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 :
- not stripping the /api/ part of the URL :
location /api/ {
proxy_pass 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.
- stripping the /api/ part of the URL on the proxy_server
location /api/ {
proxy_pass 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.