0

Angular always returns the index.html file content as a response (instead of JSON data) when calling NestJS (NodeJS) APIs with an Nginx reverse proxy when I access to my webapp from a public IP x.x.x.x but when I access it from localhost (same machine where Nginx is installed), everything works well.

Here is my nginx.conf content:

server {
    listen      80;
    listen [::]:80;

    server_name _;
    root   C:/Project/front;

    location / {
        index index.html;
        try_files $uri $uri/ /index.html;
    }

    location /api/ {
        rewrite ^/api/(.*)$ /$1 break;
        proxy_pass http://localhost:3001/;
    }
    
}

Appreciate your help. Thanks !

MHDaouas
  • 159
  • 2
  • 13
  • Btw I ran nodejs with 'node main.js --host=0.0.0.0' – MHDaouas Apr 03 '23 at 22:44
  • Hi there! Just to have a little bit of context...Is NestJS API exposed on /api path? If that's not the case...did you try removing the rewrite nginx rule? For example...just using: location /api { proxy_pass http:// localhost:3001} (blank space must be removed) – lmoglia Apr 04 '23 at 00:21
  • Yes NestJS API is exposed behind /api path. My problem is that it seems like it's interpreted as an Angular page instead of an API. – MHDaouas Apr 04 '23 at 06:23

0 Answers0