简体   繁体   English

使用EggJS:部署后访问接口一直报502 bad gateway的错误

[英]used EggJS: After deployment, the access interface always reports an error of 502 bad gateway

What happens?怎么了?

The project can be deployed successfully without any error, but when I request the interface, nginx will feed back the error项目可以部署成功,没有报错,但是我请求接口的时候,nginx会反馈错误

upstream prematurely closed connection while reading response header from upstream, client: 171.221.xxx.xxx, server: api.example.club, request: "GET /api/webInfo HTTP/1.1", upstream: "http://127.0.0.1:7111/api/webInfo", host: "api.example.club"

Then I tried to change the configuration, but it still didn't take effect: the configuration is as follows然后尝试更改配置,还是没有生效:配置如下

config.default.ts配置.default.ts

config.proxy = true;

config.httpclient = {
    request: {
        timeout: 50000,
    },
    httpAgent: {
        freeSocketTimeout: 40000,
    },
    httpsAgent: {
        freeSocketTimeout: 40000,
    },
};

app.ts应用程序.ts

import { Application, IBoot } from 'egg';

export default class FooBoot implements IBoot {
  private readonly app: Application;

  constructor(app: Application) {
    this.app = app;
  }

  async serverDidReady() {
    this.app.server.timeout = 0
    this.app.server.keepAliveTimeout = 0
  }

}

Nginx config Nginx 配置

server
{
    listen 80;
    server_name api.example.club;
    index index.html index.htm default.htm default.html;
    #root /www/wwwroot/blog-server;
    
    #SSL-START
    #error_page 404/404.html;
    
    #SSL-END
    
    #ERROR-PAGE-START
    #error_page 404 /404.html;
    #error_page 502 /502.html;
    #ERROR-PAGE-END
    
    
    #REWRITE-START
    include /www/server/panel/vhost/rewrite/node_server.conf;
    #REWRITE-END
    
    location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md|package.json|package-lock.json|\.env|node_modules) {
        return 404;
    }
    
    
    location /.well-known/ {
        root  /www/wwwroot/server;
    }

    
    location ~ /purge(/.*) {
        proxy_cache_purge cache_one $host$request_uri$is_args$args;
    }

    location / {
        proxy_pass http://127.0.0.1:7111;
        proxy_set_header Host $host:$server_port;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header REMOTE-HOST $remote_addr;
        add_header X-Cache $upstream_cache_status;

        proxy_connect_timeout 30s;
        proxy_read_timeout 86400s;
        proxy_send_timeout 30s;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
   
    
    access_log  /www/wwwlogs/server.log;
    error_log  /www/wwwlogs/server.error.log;
}

Mini Showcase Repository(REQUIRED)迷你展示库(必需)

Code address代码地址

https://github.com/Shen120/rp_egg https://github.com/Shen120/rp_egg

How To Reproduce如何重现

Steps to reproduce the behavior:重现该行为的步骤:

  1. Run after deployment部署后运行
  2. Then request the interface然后请求接口

Expected behavior 1.It can be accessed normally, and 502 no longer appears预期行为1.可以正常访问,不再出现502

Context语境

  • Node Version :14.17.1节点版本:14.17.1
  • Egg Version :2.33.1彩蛋版本:2.33.1
  • egg-bin :4.16.4蛋箱:4.16.4
  • egg-cors :2.2.3蛋心:2.2.3
  • Platform : liunx平台:liunx

I got it,Because my service is configured with HTTPS, but the address of the reverse proxy is HTTP, so 502明白了,因为我的服务配置的是HTTPS,但是反向代理的地址是HTTP,所以502

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM