I have this basic nginx server block configuration which is made to serve a static frontend and a node application (api).
<code> listen 80;
listen [::]:80;
server_name app.sample.com;
root /var/www/front-staging/dist;
index index.html;
try_files $uri $uri/ /index.html;
location /api/ {
allow all;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://127.0.0.1:4020/;
}
</code>
<code> listen 80;
listen [::]:80;
server_name app.sample.com;
root /var/www/front-staging/dist;
index index.html;
try_files $uri $uri/ /index.html;
location /api/ {
allow all;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://127.0.0.1:4020/;
}
</code>
listen 80;
listen [::]:80;
server_name app.sample.com;
root /var/www/front-staging/dist;
index index.html;
try_files $uri $uri/ /index.html;
location /api/ {
allow all;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://127.0.0.1:4020/;
}
I can reach the frontend and I know that the node (fastify) application is correctly running on localhost:4020.
The problem is that I can’t reach the server side path through the location /api/ and I receive 404 instead. I’m already struggling enough and I can’t get out. I’m sure that the node application is reachable because If I specify it as root I can see it correctly.