I have two applications: HTML+JS frontend and PHP backend. I would like to set Nginx up so that both are served from the same domain. Requests to the backend are made uing URLs starting with /api
.
My attempt was this:
server {
root /path/to/frontend;
index index.html;
server_name example.com;
location / {
try_files $uri $uri/ /index.html;
}
location /api {
alias /path/to/backend;
index index.php;
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
}
However, for all requests to the backend, I end up with a 404: primary script unknown.
Is there a way to achieve what I'm trying to do here? How?