将 Spring Boot 应用程序部署到 Elastic Beanstalk 时出现 502 Bad Gateway

Posted

技术标签:

【中文标题】将 Spring Boot 应用程序部署到 Elastic Beanstalk 时出现 502 Bad Gateway【英文标题】:502 Bad Gateway when deploying Spring Boot application to Elastic Beanstalk 【发布时间】:2019-07-27 11:25:35 【问题描述】:

免责声明* 我知道对此有很多问题。我已经查看了它们并应用了答案,但它仍然不起作用。

我使用 .jar(不是 war)文件将 Spring Boot 应用程序部署到 Elastic Beanstalk。我正在使用 Java 1.8。我将 application.properties 更改为 server.port = 5000。我还在 0.0.0.0/32 上打开了我的 ec2 实例用于端口 5000 的安全组。当我的弹性 beantalk 环境加载时,状态变为降级。这是来自 EB 的日志文件。

-------------------------------------
/var/log/nginx/error.log
-------------------------------------
2019/03/05 21:47:12 [error] 3256#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 198.72.235.68, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "3.209.22.246"
2019/03/05 21:47:12 [error] 3256#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 198.72.235.68, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:5000/favicon.ico", host: "3.209.22.246", referrer: "http://3.209.22.246/"
2019/03/05 21:47:40 [error] 3256#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 198.72.235.68, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "3.209.22.246"
2019/03/05 21:47:40 [error] 3256#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 198.72.235.68, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:5000/favicon.ico", host: "3.209.22.246", referrer: "http://3.209.22.246/"
2019/03/05 21:47:41 [error] 3256#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 198.72.235.68, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "3.209.22.246"
2019/03/05 21:47:41 [error] 3256#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 198.72.235.68, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:5000/favicon.ico", host: "3.209.22.246", referrer: "http://3.209.22.246/"
2019/03/05 21:47:42 [error] 3256#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 198.72.235.68, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "3.209.22.246"
2019/03/05 21:47:42 [error] 3256#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 198.72.235.68, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:5000/favicon.ico", host: "3.209.22.246", referrer: "http://3.209.22.246/"
2019/03/05 21:47:42 [error] 3256#0: *6 connect() failed (111: Connection refused) while connecting to upstream, client: 198.72.235.68, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "3.209.22.246"
2019/03/05 21:47:42 [error] 3256#0: *6 connect() failed (111: Connection refused) while connecting to upstream, client: 198.72.235.68, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:5000/favicon.ico", host: "3.209.22.246", referrer: "http://3.209.22.246/"
2019/03/05 21:47:42 [error] 3256#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 198.72.235.68, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "3.209.22.246"
2019/03/05 21:47:42 [error] 3256#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 198.72.235.68, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:5000/favicon.ico", host: "3.209.22.246", referrer: "http://3.209.22.246/"
2019/03/05 21:47:42 [error] 3256#0: *6 connect() failed (111: Connection refused) while connecting to upstream, client: 198.72.235.68, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "3.209.22.246"
2019/03/05 21:47:42 [error] 3256#0: *6 connect() failed (111: Connection refused) while connecting to upstream, client: 198.72.235.68, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:5000/favicon.ico", host: "3.209.22.246", referrer: "http://3.209.22.246/"



-------------------------------------
/var/log/eb-activity.log
-------------------------------------
    inflating: /var/app/staging/resources/static/resources/logo.png  
    inflating: /var/app/staging/resources/static/resources/right.png  
    inflating: /var/app/staging/resources/static/resources/settings.png  
    inflating: /var/app/staging/.classpath  
    inflating: /var/app/staging/mvnw.cmd  
    inflating: /var/app/staging/coffee/CoffeeApplicationTests.class  
    inflating: /var/app/staging/.factorypath  
    inflating: /var/app/staging/.gitignore  
  Executing: HOME=/tmp /opt/elasticbeanstalk/lib/ruby/bin/ruby /opt/elasticbeanstalk/lib/ruby/bin/foreman export supervisord --procfile /var/app/staging/Procfile --root /var/app/current --app application --log /var/log/ --user webapp --template /opt/elasticbeanstalk/private/config/foreman/supervisord --env /var/elasticbeanstalk/staging/elasticbeanstalk.env /var/elasticbeanstalk/staging/supervisor
  [foreman export] writing: application.conf
  Executing: /opt/elasticbeanstalk/bin/log-conf -n supervisor -l'/var/log/supervisord.log' -t bundlelogs

  Executing: /opt/elasticbeanstalk/bin/log-conf -n containerlistener -l'/var/log/eb-container-listener.log' -t bundlelogs

[2019-03-05T21:43:24.963Z] INFO  [3054]  - [Application deployment springcoffeep-source@1/StartupStage0/AppDeployPreHook/01_configure_xray.sh] : Starting activity...
[2019-03-05T21:43:25.071Z] INFO  [3054]  - [Application deployment springcoffeep-source@1/StartupStage0/AppDeployPreHook/01_configure_xray.sh] : Completed activity.
[2019-03-05T21:43:25.071Z] INFO  [3054]  - [Application deployment springcoffeep-source@1/StartupStage0/AppDeployPreHook/03_configure_proxy.sh] : Starting activity...
[2019-03-05T21:43:25.249Z] INFO  [3054]  - [Application deployment springcoffeep-source@1/StartupStage0/AppDeployPreHook/03_configure_proxy.sh] : Completed activity. Result:
  Executing: /opt/elasticbeanstalk/bin/log-conf -n nginx -l'/var/log/nginx/*'

  Executing: /usr/sbin/nginx -t -c /var/elasticbeanstalk/staging/nginx/nginx.conf
  nginx: the configuration file /var/elasticbeanstalk/staging/nginx/nginx.conf syntax is ok
  nginx: configuration file /var/elasticbeanstalk/staging/nginx/nginx.conf test is successful
[2019-03-05T21:43:25.249Z] INFO  [3054]  - [Application deployment springcoffeep-source@1/StartupStage0/AppDeployPreHook] : Completed activity. Result:
  Successfully execute hooks in directory /opt/elasticbeanstalk/hooks/appdeploy/pre.
[2019-03-05T21:43:25.249Z] INFO  [3054]  - [Application deployment springcoffeep-source@1/StartupStage0/EbExtensionPostBuild] : Starting activity...
[2019-03-05T21:43:25.643Z] INFO  [3054]  - [Application deployment springcoffeep-source@1/StartupStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild] : Starting activity...
[2019-03-05T21:43:25.643Z] INFO  [3054]  - [Application deployment springcoffeep-source@1/StartupStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild] : Completed activity.
[2019-03-05T21:43:25.658Z] INFO  [3054]  - [Application deployment springcoffeep-source@1/StartupStage0/EbExtensionPostBuild] : Completed activity.
[2019-03-05T21:43:25.658Z] INFO  [3054]  - [Application deployment springcoffeep-source@1/StartupStage0/InfraCleanEbExtension] : Starting activity...
[2019-03-05T21:43:25.659Z] INFO  [3054]  - [Application deployment springcoffeep-source@1/StartupStage0/InfraCleanEbExtension] : Completed activity. Result:
  Cleaned ebextensions subdirectories from /var/app/staging.
[2019-03-05T21:43:25.659Z] INFO  [3054]  - [Application deployment springcoffeep-source@1/StartupStage0] : Completed activity. Result:
  Application deployment - Command CMD-Startup stage 0 completed
[2019-03-05T21:43:25.659Z] INFO  [3054]  - [Application deployment springcoffeep-source@1/StartupStage1] : Starting activity...
[2019-03-05T21:43:25.659Z] INFO  [3054]  - [Application deployment springcoffeep-source@1/StartupStage1/AppDeployEnactHook] : Starting activity...
[2019-03-05T21:43:25.659Z] INFO  [3054]  - [Application deployment springcoffeep-source@1/StartupStage1/AppDeployEnactHook/01_stop_before_promote.sh] : Starting activity...
[2019-03-05T21:43:26.233Z] INFO  [3054]  - [Application deployment springcoffeep-source@1/StartupStage1/AppDeployEnactHook/01_stop_before_promote.sh] : Completed activity. Result:
  Executing: /usr/local/bin/supervisorctl -c /etc/supervisor/supervisord.conf stop application:*
  unix:///tmp/supervisor.sock no such file
  Executing: /usr/local/bin/supervisorctl -c /etc/supervisor/supervisord.conf stop all
  unix:///tmp/supervisor.sock no such file
  Executing: /sbin/status supervisord
  supervisord stop/waiting
[2019-03-05T21:43:26.233Z] INFO  [3054]  - [Application deployment springcoffeep-source@1/StartupStage1/AppDeployEnactHook/01stop_xray.sh] : Starting activity...
[2019-03-05T21:43:28.349Z] INFO  [3054]  - [Application deployment springcoffeep-source@1/StartupStage1/AppDeployEnactHook/01stop_xray.sh] : Completed activity. Result:
  Executing: if ( initctl status xray | grep start ); then initctl stop xray; fi
  xray start/running, process 2239
  xray stop/waiting
[2019-03-05T21:43:28.349Z] INFO  [3054]  - [Application deployment springcoffeep-source@1/StartupStage1/AppDeployEnactHook/02start_xray.sh] : Starting activity...
[2019-03-05T21:43:28.456Z] INFO  [3054]  - [Application deployment springcoffeep-source@1/StartupStage1/AppDeployEnactHook/02start_xray.sh] : Completed activity.
[2019-03-05T21:43:28.456Z] INFO  [3054]  - [Application deployment springcoffeep-source@1/StartupStage1/AppDeployEnactHook/03_stop_proxy.sh] : Starting activity...
[2019-03-05T21:43:28.574Z] INFO  [3054]  - [Application deployment springcoffeep-source@1/StartupStage1/AppDeployEnactHook/03_stop_proxy.sh] : Completed activity. Result:
  Executing: service nginx stop

[2019-03-05T21:43:28.574Z] INFO  [3054]  - [Application deployment springcoffeep-source@1/StartupStage1/AppDeployEnactHook/05_promote_application.sh] : Starting activity...
[2019-03-05T21:43:28.675Z] INFO  [3054]  - [Application deployment springcoffeep-source@1/StartupStage1/AppDeployEnactHook/05_promote_application.sh] : Completed activity.
[2019-03-05T21:43:28.675Z] INFO  [3054]  - [Application deployment springcoffeep-source@1/StartupStage1/AppDeployEnactHook/07_start_application.sh] : Starting activity...
[2019-03-05T21:43:28.780Z] INFO  [3054]  - [Application deployment springcoffeep-source@1/StartupStage1/AppDeployEnactHook/07_start_application.sh] : Completed activity. Result:
  Executing: /sbin/start supervisord
  supervisord start/running, process 3207
[2019-03-05T21:43:28.780Z] INFO  [3054]  - [Application deployment springcoffeep-source@1/StartupStage1/AppDeployEnactHook/09_start_proxy.sh] : Starting activity...
[2019-03-05T21:43:31.379Z] INFO  [3054]  - [Application deployment springcoffeep-source@1/StartupStage1/AppDeployEnactHook/09_start_proxy.sh] : Completed activity. Result:
  Executing: service nginx stop

  Executing: service nginx start
  Starting nginx: [  OK  ]
  Executing: /opt/elasticbeanstalk/bin/healthd-track-pidfile --proxy nginx

  Executing: /opt/elasticbeanstalk/bin/healthd-configure --appstat-log-path /var/log/nginx/healthd/application.log --appstat-unit sec --appstat-timestamp-on 'completion'

  Executing: /opt/elasticbeanstalk/bin/healthd-restart

[2019-03-05T21:43:31.379Z] INFO  [3054]  - [Application deployment springcoffeep-source@1/StartupStage1/AppDeployEnactHook/11_stop_after_promote.sh] : Starting activity...
[2019-03-05T21:43:31.588Z] INFO  [3054]  - [Application deployment springcoffeep-source@1/StartupStage1/AppDeployEnactHook/11_stop_after_promote.sh] : Completed activity.
[2019-03-05T21:43:31.588Z] INFO  [3054]  - [Application deployment springcoffeep-source@1/StartupStage1/AppDeployEnactHook] : Completed activity. Result:
  Successfully execute hooks in directory /opt/elasticbeanstalk/hooks/appdeploy/enact.
[2019-03-05T21:43:31.588Z] INFO  [3054]  - [Application deployment springcoffeep-source@1/StartupStage1/AppDeployPostHook] : Starting activity...
[2019-03-05T21:43:31.588Z] INFO  [3054]  - [Application deployment springcoffeep-source@1/StartupStage1/AppDeployPostHook] : Completed activity. Result:
  Successfully execute hooks in directory /opt/elasticbeanstalk/hooks/appdeploy/post.
[2019-03-05T21:43:31.588Z] INFO  [3054]  - [Application deployment springcoffeep-source@1/StartupStage1/PostInitHook] : Starting activity...
[2019-03-05T21:43:31.588Z] INFO  [3054]  - [Application deployment springcoffeep-source@1/StartupStage1/PostInitHook] : Completed activity. Result:
  Successfully execute hooks in directory /opt/elasticbeanstalk/hooks/postinit.
[2019-03-05T21:43:31.588Z] INFO  [3054]  - [Application deployment springcoffeep-source@1/StartupStage1] : Completed activity. Result:
  Application deployment - Command CMD-Startup stage 1 completed
[2019-03-05T21:43:31.589Z] INFO  [3054]  - [Application deployment springcoffeep-source@1/AddonsAfter] : Starting activity...
[2019-03-05T21:43:31.589Z] INFO  [3054]  - [Application deployment springcoffeep-source@1/AddonsAfter/ConfigLogRotation] : Starting activity...
[2019-03-05T21:43:31.589Z] INFO  [3054]  - [Application deployment springcoffeep-source@1/AddonsAfter/ConfigLogRotation/10-config.sh] : Starting activity...
[2019-03-05T21:43:31.929Z] INFO  [3054]  - [Application deployment springcoffeep-source@1/AddonsAfter/ConfigLogRotation/10-config.sh] : Completed activity. Result:
  Disabled forced hourly log rotation.
[2019-03-05T21:43:31.929Z] INFO  [3054]  - [Application deployment springcoffeep-source@1/AddonsAfter/ConfigLogRotation] : Completed activity. Result:
  Successfully execute hooks in directory /opt/elasticbeanstalk/addons/logpublish/hooks/config.
[2019-03-05T21:43:31.929Z] INFO  [3054]  - [Application deployment springcoffeep-source@1/AddonsAfter] : Completed activity.
[2019-03-05T21:43:31.929Z] INFO  [3054]  - [Application deployment springcoffeep-source@1] : Completed activity. Result:
  Application deployment - Command CMD-Startup succeeded
[2019-03-05T21:48:01.292Z] INFO  [3491]  - [CMD-TailLogs] : Starting activity...
[2019-03-05T21:48:01.293Z] INFO  [3491]  - [CMD-TailLogs/AddonsBefore] : Starting activity...
[2019-03-05T21:48:01.293Z] INFO  [3491]  - [CMD-TailLogs/AddonsBefore] : Completed activity.
[2019-03-05T21:48:01.293Z] INFO  [3491]  - [CMD-TailLogs/TailLogs] : Starting activity...
[2019-03-05T21:48:01.293Z] INFO  [3491]  - [CMD-TailLogs/TailLogs/TailLogs] : Starting activity...



-------------------------------------
/var/log/nginx/access.log
-------------------------------------
198.72.235.68 - - [05/Mar/2019:21:47:12 +0000] "GET / HTTP/1.1" 502 575 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (Khtml, like Gecko) Chrome/72.0.3626.119 Safari/537.36" "-"
198.72.235.68 - - [05/Mar/2019:21:47:12 +0000] "GET /favicon.ico HTTP/1.1" 502 575 "http://3.209.22.246/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36" "-"
198.72.235.68 - - [05/Mar/2019:21:47:40 +0000] "GET / HTTP/1.1" 502 575 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36" "-"
198.72.235.68 - - [05/Mar/2019:21:47:40 +0000] "GET /favicon.ico HTTP/1.1" 502 575 "http://3.209.22.246/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36" "-"
198.72.235.68 - - [05/Mar/2019:21:47:41 +0000] "GET / HTTP/1.1" 502 575 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36" "-"
198.72.235.68 - - [05/Mar/2019:21:47:41 +0000] "GET /favicon.ico HTTP/1.1" 502 575 "http://3.209.22.246/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36" "-"
198.72.235.68 - - [05/Mar/2019:21:47:42 +0000] "GET / HTTP/1.1" 502 575 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36" "-"
198.72.235.68 - - [05/Mar/2019:21:47:42 +0000] "GET /favicon.ico HTTP/1.1" 502 575 "http://3.209.22.246/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36" "-"
198.72.235.68 - - [05/Mar/2019:21:47:42 +0000] "GET / HTTP/1.1" 502 575 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36" "-"
198.72.235.68 - - [05/Mar/2019:21:47:42 +0000] "GET /favicon.ico HTTP/1.1" 502 575 "http://3.209.22.246/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36" "-"
198.72.235.68 - - [05/Mar/2019:21:47:42 +0000] "GET / HTTP/1.1" 502 575 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36" "-"
198.72.235.68 - - [05/Mar/2019:21:47:42 +0000] "GET /favicon.ico HTTP/1.1" 502 575 "http://3.209.22.246/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36" "-"
198.72.235.68 - - [05/Mar/2019:21:47:42 +0000] "GET / HTTP/1.1" 502 575 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36" "-"
198.72.235.68 - - [05/Mar/2019:21:47:42 +0000] "GET /favicon.ico HTTP/1.1" 502 575 "http://3.209.22.246/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36" "-"



-------------------------------------
/var/log/eb-commandprocessor.log
-------------------------------------
[2019-03-05T21:42:54.163Z] DEBUG [2834]  : Retrieving metadata for key: AWS::ElasticBeanstalk::Ext||ManifestFileS3Key..
[2019-03-05T21:42:54.412Z] INFO  [2834]  : Finding latest manifest from bucket 'elasticbeanstalk-us-east-1-274999247491' with prefix 'resources/environments/e-xdvtnscapn/_runtime/versions/manifest_'.
[2019-03-05T21:42:54.523Z] INFO  [2834]  : Found manifest with key 'resources/environments/e-xdvtnscapn/_runtime/versions/manifest_1551822103235'.
[2019-03-05T21:42:54.571Z] INFO  [2834]  : Updated manifest cache: deployment ID 1 and serial 1.
[2019-03-05T21:42:54.571Z] DEBUG [2834]  : Loaded definition of Command CMD-PreInit.
[2019-03-05T21:42:54.571Z] INFO  [2834]  : Executing Initialization
[2019-03-05T21:42:54.572Z] INFO  [2834]  : Executing command: CMD-PreInit...
[2019-03-05T21:42:54.572Z] INFO  [2834]  : Executing command CMD-PreInit activities...
[2019-03-05T21:42:54.572Z] DEBUG [2834]  : Setting environment variables..
[2019-03-05T21:42:54.572Z] INFO  [2834]  : Running AddonsBefore for command CMD-PreInit...
[2019-03-05T21:42:58.783Z] DEBUG [2834]  : Running stages of Command CMD-PreInit from stage 0 to stage 0...
[2019-03-05T21:42:58.783Z] INFO  [2834]  : Running stage 0 of command CMD-PreInit...
[2019-03-05T21:42:58.784Z] DEBUG [2834]  : Loaded 2 actions for stage 0.
[2019-03-05T21:42:58.784Z] INFO  [2834]  : Running 1 of 2 actions: DownloadSourceBundle...
[2019-03-05T21:42:59.097Z] INFO  [2834]  : Running 2 of 2 actions: PreInitHook...
[2019-03-05T21:42:59.470Z] INFO  [2834]  : Running AddonsAfter for command CMD-PreInit...
[2019-03-05T21:42:59.470Z] INFO  [2834]  : Command CMD-PreInit succeeded!
[2019-03-05T21:42:59.471Z] INFO  [2834]  : Command processor returning results: 
"status":"SUCCESS","api_version":"1.0","results":["status":"SUCCESS","msg":"","returncode":0,"events":[]]
[2019-03-05T21:43:23.285Z] DEBUG [3054]  : Reading config file: /etc/elasticbeanstalk/.aws-eb-stack.properties
[2019-03-05T21:43:23.286Z] DEBUG [3054]  : Checking if the command processor should execute...
[2019-03-05T21:43:23.288Z] DEBUG [3054]  : Checking whether the command is applicable to instance (i-0090acbe1f680bed4)..
[2019-03-05T21:43:23.288Z] INFO  [3054]  : Command is applicable to this instance (i-0090acbe1f680bed4)..
[2019-03-05T21:43:23.288Z] DEBUG [3054]  : Checking if the received command stage is valid..
[2019-03-05T21:43:23.288Z] INFO  [3054]  : No stage_num in command. Valid stage..
[2019-03-05T21:43:23.288Z] INFO  [3054]  : Received command CMD-Startup: "execution_data"=>"\"leader_election\":\"true\"", "instance_ids"=>["i-0090acbe1f680bed4"], "command_name"=>"CMD-Startup", "api_version"=>"1.0", "resource_name"=>"AWSEBAutoScalingGroup", "request_id"=>"74447fa8-3f8f-11e9-8e18-53c93173e114"
[2019-03-05T21:43:23.288Z] INFO  [3054]  : Command processor should execute command.
[2019-03-05T21:43:23.288Z] DEBUG [3054]  : Storing current stage..
[2019-03-05T21:43:23.288Z] DEBUG [3054]  : Stage_num does not exist. Not saving null stage. Returning..
[2019-03-05T21:43:23.288Z] DEBUG [3054]  : Reading config file: /etc/elasticbeanstalk/.aws-eb-stack.properties
[2019-03-05T21:43:23.289Z] DEBUG [3054]  : Retrieving metadata for key: AWS::ElasticBeanstalk::Ext||_ContainerConfigFileContent||commands..
[2019-03-05T21:43:23.289Z] DEBUG [3054]  : Retrieving metadata for key: AWS::ElasticBeanstalk::Ext||_API||_Commands..
[2019-03-05T21:43:23.290Z] INFO  [3054]  : Found enabled addons: ["logstreaming", "logpublish"].
[2019-03-05T21:43:23.291Z] INFO  [3054]  : Updating Command definition of addon logstreaming.
[2019-03-05T21:43:23.291Z] INFO  [3054]  : Updating Command definition of addon logpublish.
[2019-03-05T21:43:23.291Z] DEBUG [3054]  : Refreshing metadata...
[2019-03-05T21:43:23.629Z] DEBUG [3054]  : Refreshed environment metadata.
[2019-03-05T21:43:23.630Z] INFO  [3054]  : Recreated directory /opt/elasticbeanstalk/deploy/configuration/.
[2019-03-05T21:43:23.630Z] DEBUG [3054]  : Retrieving metadata for key: AWS::ElasticBeanstalk::Ext||_AppSourceUrlFileContent||url..
[2019-03-05T21:43:23.630Z] INFO  [3054]  : Created appsource url file at /opt/elasticbeanstalk/deploy/configuration/appsourceurl.
[2019-03-05T21:43:23.630Z] DEBUG [3054]  : Retrieving metadata for key: AWS::ElasticBeanstalk::Ext||_ContainerConfigFileContent..
[2019-03-05T21:43:23.631Z] INFO  [3054]  : Created container config file at /opt/elasticbeanstalk/deploy/configuration/containerconfiguration.
[2019-03-05T21:43:23.631Z] DEBUG [3054]  : Retrieving metadata for key: AWS::ElasticBeanstalk::Ext||_ContainerConfigFileContent||commands..
[2019-03-05T21:43:23.632Z] DEBUG [3054]  : Retrieving metadata for key: AWS::ElasticBeanstalk::Ext||_API||_Commands..
[2019-03-05T21:43:23.633Z] INFO  [3054]  : Found enabled addons: ["logstreaming", "logpublish"].
[2019-03-05T21:43:23.633Z] INFO  [3054]  : Updating Command definition of addon logstreaming.
[2019-03-05T21:43:23.634Z] INFO  [3054]  : Updating Command definition of addon logpublish.
[2019-03-05T21:43:23.634Z] DEBUG [3054]  : Loaded definition of Command CMD-Startup.
[2019-03-05T21:43:23.634Z] INFO  [3054]  : Executing Application deployment
[2019-03-05T21:43:23.634Z] INFO  [3054]  : Executing command: CMD-Startup...
[2019-03-05T21:43:23.634Z] INFO  [3054]  : Executing command CMD-Startup activities...
[2019-03-05T21:43:23.634Z] DEBUG [3054]  : Setting environment variables..
[2019-03-05T21:43:23.634Z] INFO  [3054]  : Running AddonsBefore for command CMD-Startup...
[2019-03-05T21:43:23.754Z] DEBUG [3054]  : Running stages of Command CMD-Startup from stage 0 to stage 1...
[2019-03-05T21:43:23.754Z] INFO  [3054]  : Running stage 0 of command CMD-Startup...
[2019-03-05T21:43:23.754Z] INFO  [3054]  : Running leader election...
[2019-03-05T21:43:24.091Z] INFO  [3054]  : Instance is Leader.
[2019-03-05T21:43:24.091Z] DEBUG [3054]  : Loaded 7 actions for stage 0.
[2019-03-05T21:43:24.091Z] INFO  [3054]  : Running 1 of 7 actions: HealthdLogRotation...
[2019-03-05T21:43:24.097Z] INFO  [3054]  : Running 2 of 7 actions: HealthdHTTPDLogging...
[2019-03-05T21:43:24.097Z] INFO  [3054]  : Running 3 of 7 actions: HealthdNginxLogging...
[2019-03-05T21:43:24.097Z] INFO  [3054]  : Running 4 of 7 actions: EbExtensionPreBuild...
[2019-03-05T21:43:24.507Z] INFO  [3054]  : Running 5 of 7 actions: AppDeployPreHook...
[2019-03-05T21:43:25.249Z] INFO  [3054]  : Running 6 of 7 actions: EbExtensionPostBuild...
[2019-03-05T21:43:25.658Z] INFO  [3054]  : Running 7 of 7 actions: InfraCleanEbExtension...
[2019-03-05T21:43:25.659Z] INFO  [3054]  : Running stage 1 of command CMD-Startup...
[2019-03-05T21:43:25.659Z] DEBUG [3054]  : Loaded 3 actions for stage 1.
[2019-03-05T21:43:25.659Z] INFO  [3054]  : Running 1 of 3 actions: AppDeployEnactHook...
[2019-03-05T21:43:31.588Z] INFO  [3054]  : Running 2 of 3 actions: AppDeployPostHook...
[2019-03-05T21:43:31.588Z] INFO  [3054]  : Running 3 of 3 actions: PostInitHook...
[2019-03-05T21:43:31.588Z] INFO  [3054]  : Running AddonsAfter for command CMD-Startup...
[2019-03-05T21:43:31.929Z] INFO  [3054]  : Command CMD-Startup succeeded!
[2019-03-05T21:43:31.930Z] INFO  [3054]  : Command processor returning results: 
"status":"SUCCESS","api_version":"1.0","results":["status":"SUCCESS","msg":"","returncode":0,"events":[]]
[2019-03-05T21:48:01.284Z] DEBUG [3491]  : Reading config file: /etc/elasticbeanstalk/.aws-eb-stack.properties
[2019-03-05T21:48:01.285Z] DEBUG [3491]  : Checking if the command processor should execute...
[2019-03-05T21:48:01.289Z] DEBUG [3491]  : Checking whether the command is applicable to instance (i-0090acbe1f680bed4)..
[2019-03-05T21:48:01.289Z] INFO  [3491]  : Command is applicable to this instance (i-0090acbe1f680bed4)..
[2019-03-05T21:48:01.289Z] DEBUG [3491]  : Checking if the received command stage is valid..
[2019-03-05T21:48:01.289Z] INFO  [3491]  : No stage_num in command. Valid stage..
[2019-03-05T21:48:01.289Z] INFO  [3491]  : Received command CMD-TailLogs: "execution_data"=>"*", "instance_ids"=>["i-0090acbe1f680bed4"], "data"=>"5813e539-3f90-11e9-89f6-2fc23d76b855", "command_name"=>"CMD-TailLogs", "api_version"=>"1.0", "resource_name"=>"AWSEBAutoScalingGroup", "request_id"=>"5813e539-3f90-11e9-89f6-2fc23d76b855"
[2019-03-05T21:48:01.289Z] INFO  [3491]  : Command processor should execute command.
[2019-03-05T21:48:01.289Z] DEBUG [3491]  : Storing current stage..
[2019-03-05T21:48:01.289Z] DEBUG [3491]  : Stage_num does not exist. Not saving null stage. Returning..
[2019-03-05T21:48:01.289Z] DEBUG [3491]  : Reading config file: /etc/elasticbeanstalk/.aws-eb-stack.properties
[2019-03-05T21:48:01.289Z] DEBUG [3491]  : Retrieving metadata for key: AWS::ElasticBeanstalk::Ext||_ContainerConfigFileContent||commands..
[2019-03-05T21:48:01.290Z] DEBUG [3491]  : Retrieving metadata for key: AWS::ElasticBeanstalk::Ext||_API||_Commands..
[2019-03-05T21:48:01.291Z] INFO  [3491]  : Found enabled addons: ["logstreaming", "logpublish"].
[2019-03-05T21:48:01.292Z] INFO  [3491]  : Updating Command definition of addon logstreaming.
[2019-03-05T21:48:01.292Z] INFO  [3491]  : Updating Command definition of addon logpublish.
[2019-03-05T21:48:01.292Z] DEBUG [3491]  : Loaded definition of Command CMD-TailLogs.
[2019-03-05T21:48:01.292Z] INFO  [3491]  : Executing CMD-TailLogs
[2019-03-05T21:48:01.292Z] INFO  [3491]  : Executing command: CMD-TailLogs...
[2019-03-05T21:48:01.292Z] INFO  [3491]  : Executing command CMD-TailLogs activities...
[2019-03-05T21:48:01.292Z] DEBUG [3491]  : Setting environment variables..
[2019-03-05T21:48:01.293Z] INFO  [3491]  : Running AddonsBefore for command CMD-TailLogs...
[2019-03-05T21:48:01.293Z] DEBUG [3491]  : Running stages of Command CMD-TailLogs from stage 0 to stage 0...
[2019-03-05T21:48:01.293Z] INFO  [3491]  : Running stage 0 of command CMD-TailLogs...
[2019-03-05T21:48:01.293Z] DEBUG [3491]  : Loaded 1 actions for stage 0.
[2019-03-05T21:48:01.29

3Z] INFO  [3491]  : Running 1 of 1 actions: TailLogs...

【问题讨论】:

【参考方案1】:

最可能的情况是应用程序服务器(嵌入 Spring Boot)没有正确启动。应用服务器的日志存储到/var/log/web-1.log,也可以通过 ElasticBeanstalk 中的 Logs 选项卡获得。

根据我的经验,这通常与无法访问支持的服务(数据库集群)有关。可能从您的 ElasticBeanstalk、EC2 环境到 RDS 数据库的安全组设置不正确。

【讨论】:

让我试试 RDS 安全组。 哇..这太简单了,我不敢相信我在这上面花了这么多时间...为我的 RDS 实例打开了安全组,它可以工作了。谢谢兄弟。 你是个天才

以上是关于将 Spring Boot 应用程序部署到 Elastic Beanstalk 时出现 502 Bad Gateway的主要内容,如果未能解决你的问题,请参考以下文章

将 Spring Boot 应用程序部署到 AWS beanstalk

将 WAR 部署到 Tomcat(Spring Boot + Angular)

将 Spring Boot 应用程序部署到 AWS Beanstalk

如何将 Spring Boot 部署到 Cloud Foundry?

无法将 Spring Boot 应用程序部署到 Azure

将 Spring Boot - Angular 应用程序部署到 digitalocean