如何解决 nginx 502 bad-gateway 错误

how to resolve nginx 502 bad-gateway error

我已经将 next.js Web 应用程序容器化并托管在 aws ec-2 中。使用 nginx 作为代理服务器

这是唯一有效的页面

/

不适用于任何其他页面(路径),它抛出 502 bad-gate-way

EX:

/etc

/slug/page

这是nginx配置

server {
listen 80 default_server;


location  / {
  proxy_pass http://localhost:300;
}

}

如何将所有路径转发到特定端口?

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

        root /var/www/html;
        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                # reverse proxy for next server
                proxy_pass http://localhost:300;
                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;

            # we need to remove this 404 handling
                # because next's _next folder and own handling
                # try_files $uri $uri/ =404;
        } 

        location ~ /.well-known {
                allow all
        }
} 

我已经添加了这个 nginx 配置,现在它工作正常。