简体   繁体   中英

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

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

config.proxy = true;

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

app.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

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

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

Context

  • Node Version :14.17.1
  • Egg Version :2.33.1
  • egg-bin :4.16.4
  • egg-cors :2.2.3
  • Platform : liunx

I got it,Because my service is configured with HTTPS, but the address of the reverse proxy is HTTP, so 502

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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