【问题标题】:Unable to access spring boot application hosted on EBS无法访问托管在 EBS 上的 Spring Boot 应用程序
【发布时间】:2018-01-13 12:40:27
【问题描述】:

我在 AWS elastic-beanstalk 上托管了我的 Spring Boot 应用程序,但是当我尝试使用公共 URL 访问它时,它给了我 502 网关错误。 在日志中,我可以看到以下错误: 2017/08/05 20:10:33 [错误] 22965#0: *157 连接()失败(111:连接被拒绝)而 连接到上游,客户端:XXX.68.241.XXX,服务器:,请求:“GET /swagger-ui.html HTTP/1.1”,上游:“http://127.0.0.1:5000/swagger-ui.html”,主机: "XXXXXXXX-env.XXX.us-west-2.elasticbeanstalk.com"

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

events {
  worker_connections 1024;
}

http {
  log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
  '$status $body_bytes_sent "$http_referer" '
  '"$http_user_agent" "$http_x_forwarded_for"';


  upstream tomcat_servers{
    ip_hash;
    server 127.0.0.1:5000;
    keepalive 256;
  }

  access_log  /var/log/nginx/access.log  main;

  sendfile            on;
  tcp_nopush          on;
  tcp_nodelay         on;
  keepalive_timeout   65;
  types_hash_max_size 2048;

  include             /etc/nginx/mime.types;
  default_type        application/octet-stream;


}

【问题讨论】:

  • 安全组80端口是否开放?这是单个实例还是负载平衡后面?在公共子网上?
  • @strongjz 再次查看日志中的错误消息。与实例和安全组的连接正常。
  • @strongjz 是的 80 在安全组中打开。 nginx 正在向127.0.0.1:5000/swagger-ui.html 发送请求,但它仍然给出 502 错误
  • 您能否发布您的 nginx 配置和 beanstalk 应用程序的 .ebextensions。
  • @strongjz 我已经用 nginx 配置更新了我的问题

标签: java spring spring-boot amazon-ec2 amazon-elastic-beanstalk


【解决方案1】:

我会仔细检查您的 Spring Boot 应用程序正在运行的端口。

默认情况下,Spring Boot 应用程序将侦听端口 8080。Elastic Beanstalk 假定应用程序将侦听端口 5000。有两种方法可以解决此差异:更改 Elastic Beanstalk 配置使用的端口,或更改端口Spring Boot 应用程序监听。对于这篇文章,我们将更改 Spring Boot 应用程序侦听的端口。

最简单的方法是在 Elastic Beanstalk 环境中指定 SERVER_PORT 环境变量,并将值设置为 5000。(配置属性名称为 server.port,但 Spring Boot 允许您指定更多的环境变量 -友好名称)。

https://aws.amazon.com/blogs/devops/deploying-a-spring-boot-application-on-aws-using-aws-elastic-beanstalk/

Answered here as well

Help on how to update the port

【讨论】:

  • 我没有在 EBS 环境配置中添加端口号
猜你喜欢
  • 2018-09-05
  • 1970-01-01
  • 2020-04-28
  • 2021-12-03
  • 2015-12-15
  • 1970-01-01
  • 1970-01-01
  • 2021-03-11
  • 1970-01-01
相关资源
最近更新 更多