【发布时间】:2023-03-11 01:08:01
【问题描述】:
我已经在配置了 nginx 服务器的弹性 beanstalk 上部署了我的 nodejs rest API,我收到以下错误:
2021/03/03 15:01:15 [error] 18614#0: *1381 upstream prematurely closed connection while reading response header from upstream, client: 172.31.17.180, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8080/", host: "172.31.43.117"
2021/03/03 15:01:30 [error] 18614#0: *1385 upstream prematurely closed connection while reading response header from upstream, client: 172.31.17.180, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8080/", host: "172.31.43.117"
2021/03/03 15:01:45 [error] 18614#0: *1389 upstream prematurely closed connection while reading response header from upstream, client: 172.31.17.180, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8080/", host: "172.31.43.117"
我已经尝试了很多东西,还在我的根目录中添加了一个 .ebextensions 文件夹,其中包含一个名为 nginx.config 的文件,该文件具有以下配置,由 aws 文档提供,但它似乎仍然不起作用。我花了 3 天时间试图解决这个问题,但我无法解决。如果有人能帮我解决这个问题,我将不胜感激
我的nginx配置如下:
files:
/etc/nginx/conf.d/proxy.conf:
mode: "000644"
owner: root
group: root
content: |
upstream nodejs {
server 127.0.0.1:5000;
keepalive 256;
}
server {
listen 8080;
if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2})") {
set $year $1;
set $month $2;
set $day $3;
set $hour $4;
}
access_log /var/log/nginx/healthd/application.log.$year-$month-$day-$hour healthd;
access_log /var/log/nginx/access.log main;
location / {
proxy_pass http://nodejs;
proxy_set_header Connection "";
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
gzip on;
gzip_comp_level 4;
gzip_types text/html text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
location /static {
alias /var/app/current/static;
}
}
/opt/elasticbeanstalk/hooks/configdeploy/post/99_kill_default_nginx.sh:
mode: "000755"
owner: root
group: root
content: |
#!/bin/bash -xe
rm -f /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf
service nginx stop
service nginx start
container_commands:
removeconfig:
command: "rm -f /tmp/deployment/config/#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf
/etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf"
【问题讨论】:
标签: node.js amazon-web-services nginx