当我将 Spring Boot 应用程序部署到 AWS Elastic Beanstalk 并且无法从本地 Spring Boot 连接到 RDS 时出现 502 错误网关
Posted
技术标签:
【中文标题】当我将 Spring Boot 应用程序部署到 AWS Elastic Beanstalk 并且无法从本地 Spring Boot 连接到 RDS 时出现 502 错误网关【英文标题】:502 bad gateway when I deploy SpringBoot application to AWS Elastic Beanstalk and cannot connect to RDS from local SpringBoot 【发布时间】:2020-12-08 03:46:54 【问题描述】:我是 AWS 新手,我打算将我的 StringBoot 应用程序部署到 AWS Elastic Beanstalk。我已经创建了 rds,我可以使用 mysql 工作台成功连接到它(没有构建模式)。但是当我将它部署到 Elastic Beanstalk 并运行它时,我收到错误 502 bad gateway nginx/1.18.0。
兄弟我的另一个问题是我无法使用本地 SpringBoot 连接到 rds。所以当我把它打包成jar文件时,我让maven跳过测试部分。我的 yml(files) 如下所示。 在我发现它显示的日志中
Aug 18 22:45:10 ip-172-31-15-192 web: 2020-08-18 22:45:10.618 WARN 8134 --- [ main] o.h.e.j.e.i.JdbcEnvironmentInitiator : HHH000342: Could not obtain connection to query metadata : Unknown database 'database-myblog'
这是否意味着这个数据库有问题,还是我必须在运行它之前创建一个架构?
一些yml文件如下所示;
-
application.yml
spring:
thymeleaf:
mode: html
profiles:
active: prod
2 application-prod.yml
server:
port: 5000
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://endpoint:3306/database-myblog
username: admin
password: password
jpa:
hibernate:
ddl-auto: update
show-sql: true
logging:
level:
root: warn
com.lzl: info
file:
name: log/myblog-pro.log
3.log如下所示
/var/log/web.stdout.log
----------------------------------------
Aug 18 22:45:10 ip-172-31-15-192 web: at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:118)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:1214)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1245)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:58)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:391)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:378)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1855)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1792)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1108)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
Aug 18 22:45:10 ip-172-31-15-192 web: at com.lzl.MyblogApplication.main(MyblogApplication.java:10)
Aug 18 22:45:10 ip-172-31-15-192 web: at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
Aug 18 22:45:10 ip-172-31-15-192 web: at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
Aug 18 22:45:10 ip-172-31-15-192 web: at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
Aug 18 22:45:10 ip-172-31-15-192 web: at java.base/java.lang.reflect.Method.invoke(Method.java:566)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.boot.loader.Launcher.launch(Launcher.java:51)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:52)
Aug 18 22:45:10 ip-172-31-15-192 web: 2020-08-18 22:45:10.618 WARN 8134 --- [ main] o.h.e.j.e.i.JdbcEnvironmentInitiator : HHH000342: Could not obtain connection to query metadata : Unknown database 'database-myblog'
Aug 18 22:45:10 ip-172-31-15-192 web: 2020-08-18 22:45:10.625 WARN 8134 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
Aug 18 22:45:10 ip-172-31-15-192 web: 2020-08-18 22:45:10.695 ERROR 8134 --- [ main] o.s.boot.SpringApplication : Application run failed
Aug 18 22:45:10 ip-172-31-15-192 web: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1796)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1108)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
Aug 18 22:45:10 ip-172-31-15-192 web: at com.lzl.MyblogApplication.main(MyblogApplication.java:10)
Aug 18 22:45:10 ip-172-31-15-192 web: at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
Aug 18 22:45:10 ip-172-31-15-192 web: at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
Aug 18 22:45:10 ip-172-31-15-192 web: at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
Aug 18 22:45:10 ip-172-31-15-192 web: at java.base/java.lang.reflect.Method.invoke(Method.java:566)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.boot.loader.Launcher.launch(Launcher.java:51)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:52)
Aug 18 22:45:10 ip-172-31-15-192 web: Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
Aug 18 22:45:10 ip-172-31-15-192 web: at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:275)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:237)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.hibernate.id.factory.internal.DefaultIdentifierGeneratorFactory.injectServices(DefaultIdentifierGeneratorFactory.java:152)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.hibernate.service.internal.AbstractServiceRegistryImpl.injectDependencies(AbstractServiceRegistryImpl.java:286)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:243)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.<init>(InFlightMetadataCollectorImpl.java:176)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:118)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:1214)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1245)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:58)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:391)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:378)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1855)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1792)
Aug 18 22:45:10 ip-172-31-15-192 web: ... 24 common frames omitted
Aug 18 22:45:10 ip-172-31-15-192 web: Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
Aug 18 22:45:10 ip-172-31-15-192 web: at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:100)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:54)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:137)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:101)
Aug 18 22:45:10 ip-172-31-15-192 web: at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263)
Aug 18 22:45:10 ip-172-31-15-192 web: ... 41 common frames omitted
Aug 18 22:45:14 ip-172-31-15-192 web: . ____ _ __ _ _
Aug 18 22:45:14 ip-172-31-15-192 web: /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
Aug 18 22:45:14 ip-172-31-15-192 web: ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
Aug 18 22:45:14 ip-172-31-15-192 web: \\/ ___)| |_)| | | | | || (_| | ) ) ) )
Aug 18 22:45:14 ip-172-31-15-192 web: ' |____| .__|_| |_|_| |_\__, | / / / /
Aug 18 22:45:14 ip-172-31-15-192 web: =========|_|==============|___/=/_/_/_/
Aug 18 22:45:14 ip-172-31-15-192 web: :: Spring Boot :: (v2.2.7.RELEASE)
Aug 18 22:45:15 ip-172-31-15-192 web: 2020-08-18 22:45:15.213 INFO 8167 --- [ main] com.lzl.MyblogApplication : Starting MyblogApplication v0.0.1-SNAPSHOT on ip-172-31-15-192.us-east-2.compute.internal with PID 8167 (/var/app/current/application.jar started by webapp in /var/app/current)
Aug 18 22:45:15 ip-172-31-15-192 web: 2020-08-18 22:45:15.236 INFO 8167 --- [ main] com.lzl.MyblogApplication : The following profiles are active: prod
----------------------------------------
/var/log/nginx/access.log
----------------------------------------
83.97.20.130 - - [18/Aug/2020:19:18:39 +0000] "GET / HTTP/1.1" 200 2197 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:76.0) Gecko/20100101 Firefox/76.0" "-"
71.88.108.155 - - [18/Aug/2020:19:27:54 +0000] "GET / HTTP/1.1" 502 559 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36" "-"
71.88.108.155 - - [18/Aug/2020:19:27:54 +0000] "GET /favicon.ico HTTP/1.1" 502 559 "http://myblogsylas-env.eba-t2rnydtb.us-east-2.elasticbeanstalk.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36" "-"
209.17.97.82 - - [18/Aug/2020:20:39:36 +0000] "GET / HTTP/1.0" 502 157 "-" "Mozilla/5.0 (compatible; Nimbostratus-Bot/v1.3.2; http://cloudsystemnetworks.com)" "-"
71.88.108.155 - - [18/Aug/2020:21:28:16 +0000] "GET / HTTP/1.1" 502 559 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36" "-"
71.88.108.155 - - [18/Aug/2020:21:28:16 +0000] "GET /favicon.ico HTTP/1.1" 502 559 "http://myblogsylas-env.eba-t2rnydtb.us-east-2.elasticbeanstalk.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36" "-"
71.88.108.155 - - [18/Aug/2020:21:31:39 +0000] "GET / HTTP/1.1" 502 559 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36" "-"
71.88.108.155 - - [18/Aug/2020:21:31:39 +0000] "GET /favicon.ico HTTP/1.1" 502 559 "http://myblogsylas-env.eba-t2rnydtb.us-east-2.elasticbeanstalk.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36" "-"
71.88.108.155 - - [18/Aug/2020:21:55:47 +0000] "GET / HTTP/1.1" 502 559 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36" "-"
71.88.108.155 - - [18/Aug/2020:21:55:47 +0000] "GET /favicon.ico HTTP/1.1" 502 559 "http://myblogsylas-env.eba-t2rnydtb.us-east-2.elasticbeanstalk.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36" "-"
71.88.108.155 - - [18/Aug/2020:22:02:46 +0000] "GET / HTTP/1.1" 502 559 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36" "-"
71.88.108.155 - - [18/Aug/2020:22:02:46 +0000] "GET /favicon.ico HTTP/1.1" 502 559 "http://myblogsylas-env.eba-t2rnydtb.us-east-2.elasticbeanstalk.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36" "-"
209.17.97.2 - - [18/Aug/2020:22:03:52 +0000] "GET / HTTP/1.1" 502 157 "-" "Mozilla/5.0 (compatible; Nimbostratus-Bot/v1.3.2; http://cloudsystemnetworks.com)" "-"
102.165.30.57 - - [18/Aug/2020:22:17:34 +0000] "GET / HTTP/1.0" 502 157 "-" "NetSystemsResearch studies the availability of various services across the internet. Our website is netsystemsresearch.com" "-"
----------------------------------------
/var/log/nginx/error.log
----------------------------------------
2020/08/18 19:27:54 [error] 4712#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 71.88.108.155, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "myblogsylas-env.eba-t2rnydtb.us-east-2.elasticbeanstalk.com"
2020/08/18 19:27:54 [error] 4712#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 71.88.108.155, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:5000/favicon.ico", host: "myblogsylas-env.eba-t2rnydtb.us-east-2.elasticbeanstalk.com", referrer: "http://myblogsylas-env.eba-t2rnydtb.us-east-2.elasticbeanstalk.com/"
2020/08/18 20:39:36 [error] 4712#0: *5 connect() failed (111: Connection refused) while connecting to upstream, client: 209.17.97.82, server: , request: "GET / HTTP/1.0", upstream: "http://127.0.0.1:5000/"
2020/08/18 21:28:16 [error] 4712#0: *8 connect() failed (111: Connection refused) while connecting to upstream, client: 71.88.108.155, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "myblogsylas-env.eba-t2rnydtb.us-east-2.elasticbeanstalk.com"
2020/08/18 21:28:16 [error] 4712#0: *8 connect() failed (111: Connection refused) while connecting to upstream, client: 71.88.108.155, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:5000/favicon.ico", host: "myblogsylas-env.eba-t2rnydtb.us-east-2.elasticbeanstalk.com", referrer: "http://myblogsylas-env.eba-t2rnydtb.us-east-2.elasticbeanstalk.com/"
2020/08/18 21:31:39 [error] 6434#0: *2 connect() failed (111: Connection refused) while connecting to upstream, client: 71.88.108.155, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "myblogsylas-env.eba-t2rnydtb.us-east-2.elasticbeanstalk.com"
2020/08/18 21:31:39 [error] 6434#0: *2 connect() failed (111: Connection refused) while connecting to upstream, client: 71.88.108.155, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:5000/favicon.ico", host: "myblogsylas-env.eba-t2rnydtb.us-east-2.elasticbeanstalk.com", referrer: "http://myblogsylas-env.eba-t2rnydtb.us-east-2.elasticbeanstalk.com/"
2020/08/18 21:55:47 [error] 6434#0: *6 connect() failed (111: Connection refused) while connecting to upstream, client: 71.88.108.155, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "myblogsylas-env.eba-t2rnydtb.us-east-2.elasticbeanstalk.com"
2020/08/18 21:55:47 [error] 6434#0: *6 connect() failed (111: Connection refused) while connecting to upstream, client: 71.88.108.155, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:5000/favicon.ico", host: "myblogsylas-env.eba-t2rnydtb.us-east-2.elasticbeanstalk.com", referrer: "http://myblogsylas-env.eba-t2rnydtb.us-east-2.elasticbeanstalk.com/"
2020/08/18 22:02:46 [error] 6434#0: *9 connect() failed (111: Connection refused) while connecting to upstream, client: 71.88.108.155, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "myblogsylas-env.eba-t2rnydtb.us-east-2.elasticbeanstalk.com"
2020/08/18 22:02:46 [error] 6434#0: *9 connect() failed (111: Connection refused) while connecting to upstream, client: 71.88.108.155, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:5000/favicon.ico", host: "myblogsylas-env.eba-t2rnydtb.us-east-2.elasticbeanstalk.com", referrer: "http://myblogsylas-env.eba-t2rnydtb.us-east-2.elasticbeanstalk.com/"
2020/08/18 22:03:52 [error] 6434#0: *13 connect() failed (111: Connection refused) while connecting to upstream, client: 209.17.97.2, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "3.131.11.237:80"
2020/08/18 22:17:34 [error] 6434#0: *15 connect() failed (111: Connection refused) while connecting to upstream, client: 102.165.30.57, server: , request: "GET / HTTP/1.0", upstream: "http://127.0.0.1:5000/"
【问题讨论】:
“单击 Elastic Beanstalk 中的日志选项卡”您必须下载日志。你试过吗? @Marcin 嗨,我只是从 Elastic Beanstalk 下载日志,不知道数据库或 yml 文件哪里出了问题。 嗨。问题在于应用程序流,这将是您的应用程序。如果你 ssh 进入实例,你可以从内部卷曲它吗,例如,curl http://127.0.0.1:5000
或者它正在运行的哪个端口。
@Marcin 嗨,我不太明白“从内部卷曲它,例如 curl 127.0.0.1:5000”。我该怎么办?谢谢!
我的意思是,您确定您的应用程序可以在端口 5000 上的实例上运行吗?也许它崩溃了,或者使用了不同的端口,或者不接受任何连接?
【参考方案1】:
您需要将 Elastic Beanstalk 的安全组添加到 RDS 的入站规则中。您还可以添加您的 IP 地址以允许从本地连接。 https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/rds-external-defaultvpc.html
【讨论】:
我按照您的回答,将 EB 的安全组添加到 RDS 的入站规则(类型为 http)。但是仍然会出现同样的错误 你能用本地连接吗,比如从mysqlworkbench? 是的,我已经编辑了 RDS 安全组的入站角色,将类型设置为所有流量和来源,例如 0.0.0.0/0。我可以从没有架构的 mysql 工作台连接到 rds。 您如何在弹性 beanstalk 上指定您的 rds 连接详细信息。环境变量? 上面写着Unknown database 'database-myblog'
。你创建数据库了吗? Spring 不会为您创建它。以上是关于当我将 Spring Boot 应用程序部署到 AWS Elastic Beanstalk 并且无法从本地 Spring Boot 连接到 RDS 时出现 502 错误网关的主要内容,如果未能解决你的问题,请参考以下文章
如果我将 Spring Boot 应用程序部署到谷歌云,我应该使用应用引擎还是计算引擎 [重复]
SPRING BOOT 手动 War 文件部署到 Tomcat 并重新启动服务器,不创建数据库
如何在外部 tomcat 中部署 Spring-boot REST API
将 WAR 部署到 Tomcat(Spring Boot + Angular)