【发布时间】:2020-05-15 21:59:04
【问题描述】:
我使用 NGINX 默认配置在 AWS Elastic Beanstalk 上部署了一个带有 Node.js 后端和 React 前端的 Web 应用程序。
upstream nodejs {
server 127.0.0.1:8081;
keepalive 256;
}
server {
listen 8080;
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/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
}
我的后端在 8081 端口上运行(使用 Express.js)并且没有收到前端发出的任何调用,即fetch("http:127.0.0.1/api/volatility")。
在控制台中我看到GET https://foo-bar.us-east-1.elasticbeanstalk.com:8080/api/volatility net::ERR_CONNECTION_TIMED_OUT。
有什么办法可以解决这个问题?
【问题讨论】:
-
尝试
server nodejs:8081;(而不是上游配置中的127.0.0.1