I'm creating PHP backend app using Docker alpine-nginx, I need to redirect all requests starting with /api
to run www/index.php
file as it's built on MVC framework.
Proxy_pass works great for the rest of the site with NextJS (React, Node)
But Nginx downloads my source code instead passing it to FPM. And no other question on that topic helped me,nor moving the location block outside another location.
Do you see anything?
If I remove nested location, It runs PHP-FPM, but get error Primary script unknown" while reading response header from upstream
, trying to understand, what is wrong...
EDIT: Complete conf is here
upstream next_app {
# NextJS running app port
server nextapp:3000;
}
upstream php_fpm {
# PHP FPM server URI and port
server phpapp:9000;
}
server {
listen 80 default_server;
server_name _;
server_tokens off;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
location /api {
root /var/www;
try_files /www/index.php =404;
include fastcgi_params;
fastcgi_pass php_fpm;
}
# proxy pass for NodeJS app
proxy_http_version 1.1;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
location / {
proxy_pass http://next_app;
}
}
Now it's hitting the PHP-FPM I suppose, but telling me File not found
and FPM is logging nothing.
Nginx tells me FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream