2

I'm trying to deploy my webapplication using Angular and NestJs using Nginx on an Ubuntu remote server. I got the frontend working on https://ikse.fransenit.nl/products but cannot get the backend to work. It was working fine locally. When I try to go to /api/products I get a 502 bad gateway.

When starting the NestJS backend: nestjs starting

nginx config

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

    root /var/www/ikse/html;

    server_name ikse.fransenit.nl www.ikse.fransenit.nl;
    
    index index.html index.htm;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ /index.html;
                # proxy_pass http://localhost:8080;
                # proxy_http_version 1.1;
                # proxy_set_header Upgrade $http_upgrade;
                # proxy_set_header Connection 'upgrade';
                # proxy_set_header Host $host;
                # proxy_cache_bypass $http_upgrade;
        }

        location /api/ {
            proxy_pass https://localhost:3000;
        }

    listen [::]:443 ssl; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/ikse.fransenit.nl/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/ikse.fransenit.nl/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}

What am I missing and/or doing wrong?

Jessey Fransen
  • 135
  • 2
  • 11
  • can you try and replace localhost with 127.0.0.1 and try again and see if it works? Also change https to http (unless you have https in nodejs server) from the location - /api/ block. – SPS Jun 24 '21 at 06:58

1 Answers1

3

I don't know if you resolved it, but I think you should add /api/ at the end of https://localhost:3000 in the proxy_pass option. Because with the current configuration you need to make https://doma.in.com/api/api/profile