【发布时间】:2019-12-18 11:22:45
【问题描述】:
我正在尝试在 Elastic Beanstalk 上运行我的 Spring Boot + MySQL 应用程序。无论我尝试什么,我都会得到502 Bad Gateway。我尝试将我的 Spring Boot 端口更改为 5000,但它似乎根本没有帮助。
我尝试在application.properties 中添加server.port=5000。我也试过添加server.port=${PORT}。
每次我eb deploy 时,日志都会显示:
03:08:21.096 [main] INFO t.t.TrackMyWaterChangeApplication - Starting TrackMyWaterChangeApplication v0.0.1-SNAPSHOT on ip-172-31-41-134 with PID 6105 (/var/app/current/application.jar started by webapp in /var/app/current)
03:08:21.098 [main] INFO t.t.TrackMyWaterChangeApplication - No active profile set, falling back to default profiles: default
03:08:54.024 [main] INFO o.s.d.r.c.RepositoryConfigurationDelegate - Bootstrapping Spring Data repositories in DEFAULT mode.
03:08:56.577 [main] INFO o.s.d.r.c.RepositoryConfigurationDelegate - Finished Spring Data repository scanning in 2305ms. Found 4 repository interfaces.
03:09:20.544 [main] INFO o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$c95c6ba6] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
03:09:35.665 [main] INFO o.s.b.w.e.tomcat.TomcatWebServer - Tomcat initialized with port(s): 5000 (http)
03:09:36.122 [main] INFO o.a.coyote.http11.Http11NioProtocol - Initializing ProtocolHandler ["http-nio-5000"]
03:09:36.533 [main] INFO o.a.catalina.core.StandardService - Starting service [Tomcat]
03:09:36.533 [main] INFO o.a.catalina.core.StandardEngine - Starting Servlet engine: [Apache Tomcat/9.0.21]
03:09:39.127 [main] INFO o.a.c.c.C.[Tomcat].[localhost].[/] - Initializing Spring embedded WebApplicationContext
03:09:39.128 [main] INFO o.s.web.context.ContextLoader - Root WebApplicationContext: initialization completed in 75522 ms
03:09:59.224 [main] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Starting...
03:10:08.318 [main] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Start completed.
03:10:08.880 [main] INFO org.hibernate.Version - HHH000412: Hibernate Core {5.3.10.Final}
03:10:08.889 [main] INFO org.hibernate.cfg.Environment - HHH000205: Loaded properties from resource hibernate.properties: {hibernate.dialect=org.hibernate.dialect.MySQLDialect, hibernate.bytecode.use_reflection_optimizer=false}
03:10:09.268 [main] INFO o.h.annotations.common.Version - HCANN000001: Hibernate Commons Annotations {5.0.4.Final}
03:10:10.046 [main] INFO org.hibernate.dialect.Dialect - HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
03:10:12.003 [main] INFO o.s.o.j.LocalContainerEntityManagerFactoryBean - Initialized JPA EntityManagerFactory for persistence unit 'default'
03:10:13.291 [main] INFO o.h.h.i.QueryTranslatorFactoryInitiator - HHH000397: Using ASTQueryTranslatorFactory
03:10:14.039 [main] INFO o.s.o.j.LocalContainerEntityManagerFactoryBean - Closing JPA EntityManagerFactory for persistence unit 'default'
03:10:14.041 [main] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Shutdown initiated...
03:10:14.049 [main] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Shutdown completed.
03:10:14.063 [main] INFO o.a.catalina.core.StandardService - Stopping service [Tomcat]
我的假设是由于最后一行 (o.a.catalina.core.StandardService - Stopping service [Tomcat]),应用程序永远不会启动。当我将端口设置为 5000 时,它在本地运行时工作。要部署应用程序,我使用mvn clean package,然后使用eb deploy。如果我在我的 Windows PC 上从命令行运行打包的 JAR,它运行没有问题。这是我的pom.xml 文件的<build> 部分:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>themayoras</groupId>
<artifactId>trackmywaterchange</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>trackmywaterchange</name>
<description>Web Project for tracking water change schedules</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Hibernate Validator -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.0.17.Final</version>
</dependency>
<!-- thymeleaf -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!-- AOP -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<!-- Spring Security -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!-- SL4FJ Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>${start-class}</mainClass>
<layout>JAR</layout>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
编辑:我在/var/log/nginx/error.log 下收到一条新的日志消息,内容为
Professional SP1 x64|'|'|No|'|'|0.7d|'|'|..|'|'|AA==|'|'|112.inf|'|'|SGFjS2VkDQoxOTIuMTY4LjkyLjIyMjo1NTUyDQpEZXNrdG9wDQpjbGllbnRhLmV4ZQ0KRmFsc2UNCkZhbHNlDQpUcnVlDQpGYWxzZQ==12.act|'|'|AA=="
2019/08/11 16:48:57 [error] 1293#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 35.21.86.49, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "trackmywaterchange.us-east-2.elasticbeanstalk.com"
2019/08/11 16:48:57 [error] 1293#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 35.21.86.49, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:5000/favicon.ico", host: "trackmywaterchange.us-east-2.elasticbeanstalk.com", referrer: "http://trackmywaterchange.us-east-2.elasticbeanstalk.com/"
/var/logs/nginx/error.log下的日志
2019/08/11 03:16:33 [error] 6663#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 35.21.86.49, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:5000/favicon.ico", host: "trackmywaterchange.us-east-2.elasticbeanstalk.com", referrer: "http://trackmywaterchange.us-east-2.elasticbeanstalk.com/"
2019/08/11 05:40:09 [warn] 6663#0: *4 using uninitialized "year" variable while logging request, client: 194.32.117.3, server: , request: "GET / HTTP/1.1"
2019/08/11 05:40:09 [warn] 6663#0: *4 using uninitialized "month" variable while logging request, client: 194.32.117.3, server: , request: "GET / HTTP/1.1"
2019/08/11 05:40:09 [warn] 6663#0: *4 using uninitialized "day" variable while logging request, client: 194.32.117.3, server: , request: "GET / HTTP/1.1"
2019/08/11 05:40:09 [warn] 6663#0: *4 using uninitialized "hour" variable while logging request, client: 194.32.117.3, server: , request: "GET / HTTP/1.1"
2019/08/11 13:26:14 [warn] 6663#0: *26 using uninitialized "year" variable while logging request, client: 164.132.153.130, server: , request: "CONNECT i.instagram.com:443 HTTP/1.1"
2019/08/11 13:26:14 [warn] 6663#0: *26 using uninitialized "month" variable while logging request, client: 164.132.153.130, server: , request: "CONNECT i.instagram.com:443 HTTP/1.1"
2019/08/11 13:26:14 [warn] 6663#0: *26 using uninitialized "day" variable while logging request, client: 164.132.153.130, server: , request: "CONNECT i.instagram.com:443 HTTP/1.1"
2019/08/11 13:26:14 [warn] 6663#0: *26 using uninitialized "hour" variable while logging request, client: 164.132.153.130, server: , request: "CONNECT i.instagram.com:443 HTTP/1.1"
2019/08/11 14:30:49 [warn] 6663#0: *33 using uninitialized "year" variable while logging request, client: 110.249.212.46, server: , request: "GET http://110.249.212.46/testget?q=23333&port=80 HTTP/1.1"
2019/08/11 14:30:49 [warn] 6663#0: *33 using uninitialized "month" variable while logging request, client: 110.249.212.46, server: , request: "GET http://110.249.212.46/testget?q=23333&port=80 HTTP/1.1"
2019/08/11 14:30:49 [warn] 6663#0: *33 using uninitialized "day" variable while logging request, client: 110.249.212.46, server: , request: "GET http://110.249.212.46/testget?q=23333&port=80 HTTP/1.1"
2019/08/11 14:30:49 [warn] 6663#0: *33 using uninitialized "hour" variable while logging request, client: 110.249.212.46, server: , request: "GET http://110.249.212.46/testget?q=23333&port=80 HTTP/1.1"
2019/08/11 14:30:50 [warn] 6663#0: *32 using uninitialized "year" variable while logging request, client: 110.249.212.46, server: , request: "GET http://110.249.212.46/testget?q=23333&port=80 HTTP/1.1"
2019/08/11 14:30:50 [warn] 6663#0: *32 using uninitialized "month" variable while logging request, client: 110.249.212.46, server: , request: "GET http://110.249.212.46/testget?q=23333&port=80 HTTP/1.1"
2019/08/11 14:30:50 [warn] 6663#0: *32 using uninitialized "day" variable while logging request, client: 110.249.212.46, server: , request: "GET http://110.249.212.46/testget?q=23333&port=80 HTTP/1.1"
2019/08/11 14:30:50 [warn] 6663#0: *32 using uninitialized "hour" variable while logging request, client: 110.249.212.46, server: , request: "GET http://110.249.212.46/testget?q=23333&port=80 HTTP/1.1"
2019/08/11 14:30:58 [warn] 6663#0: *34 using uninitialized "year" variable while logging request, client: 110.249.212.46, server: , request: "GET http://110.249.212.46/testget?q=23333&port=80 HTTP/1.1"
2019/08/11 14:30:58 [warn] 6663#0: *34 using uninitialized "month" variable while logging request, client: 110.249.212.46, server: , request: "GET http://110.249.212.46/testget?q=23333&port=80 HTTP/1.1"
2019/08/11 14:30:58 [warn] 6663#0: *34 using uninitialized "day" variable while logging request, client: 110.249.212.46, server: , request: "GET http://110.249.212.46/testget?q=23333&port=80 HTTP/1.1"
2019/08/11 14:30:58 [warn] 6663#0: *34 using uninitialized "hour" variable while logging request, client: 110.249.212.46, server: , request: "GET http://110.249.212.46/testget?q=23333&port=80 HTTP/1.1"
2019/08/11 14:31:06 [warn] 6663#0: *35 using uninitialized "year" variable while logging request, client: 110.249.212.46, server: , request: "GET http://110.249.212.46/testget?q=23333&port=80 HTTP/1.1"
2019/08/11 14:31:06 [warn] 6663#0: *35 using uninitialized "month" variable while logging request, client: 110.249.212.46, server: , request: "GET http://110.249.212.46/testget?q=23333&port=80 HTTP/1.1"
2019/08/11 14:31:06 [warn] 6663#0: *35 using uninitialized "day" variable while logging request, client: 110.249.212.46, server: , request: "GET http://110.249.212.46/testget?q=23333&port=80 HTTP/1.1"
2019/08/11 14:31:06 [warn] 6663#0: *35 using uninitialized "hour" variable while logging request, client: 110.249.212.46, server: , request: "GET http://110.249.212.46/testget?q=23333&port=80 HTTP/1.1"
2019/08/11 14:33:45 [warn] 6663#0: *36 using uninitialized "year" variable while logging request, client: 66.240.205.34, server: , request: "145.ll|'|'|SGFjS2VkX0Q0OTkwNjI3|'|'|WIN-JNAPIER0859|'|'|JNapier|'|'|19-02-01|'|'||'|'|Win 7 Professional SP1 x64|'|'|No|'|'|0.7d|'|'|..|'|'|AA==|'|'|112.inf|'|'|SGFjS2VkDQoxOTIuMTY4LjkyLjIyMjo1NTUyDQpEZXNrdG9wDQpjbGllbnRhLmV4ZQ0KRmFsc2UNCkZhbHNlDQpUcnVlDQpGYWxzZQ==12.act|'|'|AA=="
2019/08/11 14:33:45 [warn] 6663#0: *36 using uninitialized "month" variable while logging request, client: 66.240.205.34, server: , request: "145.ll|'|'|SGFjS2VkX0Q0OTkwNjI3|'|'|WIN-JNAPIER0859|'|'|JNapier|'|'|19-02-01|'|'||'|'|Win 7 Professional SP1 x64|'|'|No|'|'|0.7d|'|'|..|'|'|AA==|'|'|112.inf|'|'|SGFjS2VkDQoxOTIuMTY4LjkyLjIyMjo1NTUyDQpEZXNrdG9wDQpjbGllbnRhLmV4ZQ0KRmFsc2UNCkZhbHNlDQpUcnVlDQpGYWxzZQ==12.act|'|'|AA=="
2019/08/11 14:33:45 [warn] 6663#0: *36 using uninitialized "day" variable while logging request, client: 66.240.205.34, server: , request: "145.ll|'|'|SGFjS2VkX0Q0OTkwNjI3|'|'|WIN-JNAPIER0859|'|'|JNapier|'|'|19-02-01|'|'||'|'|Win 7 Professional SP1 x64|'|'|No|'|'|0.7d|'|'|..|'|'|AA==|'|'|112.inf|'|'|SGFjS2VkDQoxOTIuMTY4LjkyLjIyMjo1NTUyDQpEZXNrdG9wDQpjbGllbnRhLmV4ZQ0KRmFsc2UNCkZhbHNlDQpUcnVlDQpGYWxzZQ==12.act|'|'|AA=="
2019/08/11 14:33:45 [warn] 6663#0: *36 using uninitialized "hour" variable while logging request, client: 66.240.205.34, server: , request: "145.ll|'|'|SGFjS2VkX0Q0OTkwNjI3|'|'|WIN-JNAPIER0859|'|'|JNapier|'|'|19-02-01|'|'||'|'|Win 7 Professional SP1 x64|'|'|No|'|'|0.7d|'|'|..|'|'|AA==|'|'|112.inf|'|'|SGFjS2VkDQoxOTIuMTY4LjkyLjIyMjo1NTUyDQpEZXNrdG9wDQpjbGllbnRhLmV4ZQ0KRmFsc2UNCkZhbHNlDQpUcnVlDQpGYWxzZQ==12.act|'|'|AA=="
2019/08/11 16:48:57 [error] 1293#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 35.21.86.49, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "trackmywaterchange.us-east-2.elasticbeanstalk.com"
2019/08/11 16:48:57 [error] 1293#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 35.21.86.49, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:5000/favicon.ico", host: "trackmywaterchange.us-east-2.elasticbeanstalk.com", referrer: "http://trackmywaterchange.us-east-2.elasticbeanstalk.com/"
/etc/nginx/nginx.conf:
user nginx;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
worker_processes auto;
worker_rlimit_nofile 32793;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
include conf.d/*.conf;
map $http_upgrade $connection_upgrade {
default "upgrade";
}
server {
listen 80 default_server;
access_log /var/log/nginx/access.log main;
client_header_timeout 60;
client_body_timeout 60;
keepalive_timeout 60;
gzip off;
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;
# Include the Elastic Beanstalk generated locations
include conf.d/elasticbeanstalk/*.conf;
}
}
【问题讨论】:
-
将日志记录级别降低到 DEBUG 看看是否有帮助
-
@YatiSawhney 我在
application.properties中设置了logging.level.org.springframework.web=DEBUG,我收到了相同的输出。我确实收到了一条新的/var/log/nginx/error.log日志消息,我已将其添加到我的帖子底部。 -
你是用nginx还是apache做代理
-
@YatiSawhney 我正在使用 nginx
-
同时上传 Nginx 日志。它们一般存储在 /var/log/nginx
标签: java spring-boot amazon-elastic-beanstalk