为此我放弃了使用 Spring Boot,因为它太脆弱了,转而采用了 Nginx 配置选项。这很有效,尽管对于仅仅制作 ZIP 来说似乎过于冗长。 Elastic Beanstalk 中还存在一个错误问题!
AWS Elastic Beanstalk Tomcat 适用于 .war,但不适用于 .zip
部署ZIP时,不会部署WAR!所以我必须创建一个解决方法来创建twoZIP 中的 WAR 文件。 (只有一个,甚至称为ROOT.war
,不起作用。)
我找不到用 Maven 创建空文件的方法,所以我创建了一个空文件empty.war
文件放在项目根目录中,并将其捆绑在 ZIP 中,以欺骗 Elastic Beanstalk 正常工作和部署应用程序。真是一团糟! OY合租!
pom.xml
<plugin> <!-- To add .ebextensions/ Nginx config for ElasticBeanstalk -->
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
assembly.xml
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>bin</id>
<baseDirectory>/</baseDirectory>
<formats>
<format>zip</format>
</formats>
<files>
<file>
<source>empty.war</source>
<outputDirectory/>
</file>
<file>
<source>${project.build.directory}/AppName-0.0.3-SNAPSHOT.war</source>
<outputDirectory/>
<destName>ROOT.war</destName>
</file>
</files>
<fileSets>
<fileSet>
<directory>${project.basedir}</directory>
<outputDirectory>/.ebextensions/nginx/conf.d/elasticbeanstalk/</outputDirectory>
<includes>
<include>force-https.conf</include>
</includes>
</fileSet>
</fileSets>
</assembly>
配置文件就在项目根目录中。我不知道还能把它放在哪里——它不是源代码。
force-ssl.conf
if ($http_x_forwarded_proto = 'http') {
return 301 https://$host$request_uri;
}
http://maven.apache.org/plugins/maven- assembly-plugin/ assembly.html