首页 > 解决方案 > 带有反向代理的 NESTJS 502 或 404

问题描述

问题:nextJS api 应用程序的 502 或 404

nestJS 适用于 url https://www.domain-name.com:3000/api/test中的端口

但是 proxy_pass http://localhost:3000; 返回 502 或 404 取决于 url

此设置适用于相同的 expressJS 应用程序。不接受 POST 或通过反向代理获取调用的 nestJS 有什么不同

这里是 nginx

server {

   server_name www.domain_name.com;

   location / {
       try_files $uri $uri/ =404;
       root /var/www/domain_name/html;
       index index.php index.html index.htm;

   }

    location /rest/v2 {
        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;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-NginX-Proxy true;
        proxy_pass http://localhost:3000;
        proxy_set_header Accept-Encoding gzip;
        proxy_set_header X-Forwarded-Proto $scheme;
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
    }

letsencrypt setup>>>> 
rest of config>>>>
}

如果我忽略了与 nestJS 服务器的连接,任何输入都将不胜感激

谢谢你。

标签: nginxnestjsbad-request

解决方案


推荐阅读