[英]used EggJS: After deployment, the access interface always reports an error of 502 bad gateway
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.proxy = true;
config.httpclient = {
request: {
timeout: 50000,
},
httpAgent: {
freeSocketTimeout: 40000,
},
httpsAgent: {
freeSocketTimeout: 40000,
},
};
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
}
}
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;
}
https://github.com/Shen120/rp_egg https://github.com/Shen120/rp_egg
Steps to reproduce the behavior:重现该行为的步骤:
Expected behavior 1.It can be accessed normally, and 502 no longer appears预期行为1.可以正常访问,不再出现502
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.