如何正确使用 Nginx deploy/setup NestJS 后端?

How to correctly deploy/setup NestJS backend using Nginx?

我正在尝试在 Ubuntu 远程服务器上使用 Angular 和使用 Nginx 的 NestJs 部署我的网络应用程序。 我让前端在 https://ikse.fransenit.nl/products 上工作,但无法让后端工作。它在当地运行良好。当我尝试去 /api/products 时,我得到一个 502 错误的网关。

启动 NestJS 后端时:

nginx 配置

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
}

我错过了什么and/or做错了什么?

我不知道你是否解决了,但我认为你应该在 proxy_pass 选项的 https://localhost:3000 末尾添加 /api/。因为使用当前配置,您需要 https://doma.in.com/api/api/profile