春季启动应用程序在Google App Engine中从HTTP重定向到HTTPS

huangapple go评论94阅读模式
英文:

Spring boot application http to https redirect in Google App Engine

问题

我有一个Spring Boot应用程序(版本2.3.0),已经成功托管在Google App Engine标准环境,并且运行良好。此门户网站拥有其自己的Google托管SSL证书。

如何将门户网站从HTTP重定向到HTTPS。

我尝试过在pom.xml中使用'<ssl-enabled>true</ssl-enabled>'选项

  1. <plugin>
  2. <groupId>com.google.cloud.tools</groupId>
  3. <artifactId>appengine-maven-plugin</artifactId>
  4. <version>2.2.0</version>
  5. <configuration>
  6. <projectId>sample-spring-boot</projectId>
  7. <version>1</version>
  8. <ssl-enabled>true</ssl-enabled>
  9. </configuration>
  10. </plugin>

也尝试过在application.properties中使用"security.require-ssl=true"

但是两者都没有重定向。有什么建议吗?

英文:

I have a spring boot application (version 2.3.0) & successfully hosted in Google App Engine standard environment & working fine. This portal has its own Google managed SSL certificate.

How to redirect the portal from http to https.

I have tried with the '&lt;ssl-enabled&gt;true&lt;/ssl-enabled&gt;' option in pom.xml

  1. &lt;plugin&gt;
  2. &lt;groupId&gt;com.google.cloud.tools&lt;/groupId&gt;
  3. &lt;artifactId&gt;appengine-maven-plugin&lt;/artifactId&gt;
  4. &lt;version&gt;2.2.0&lt;/version&gt;
  5. &lt;configuration&gt;
  6. &lt;projectId&gt;sample-spring-boot&lt;/projectId&gt;
  7. &lt;version&gt;1&lt;/version&gt;
  8. &lt;ssl-enabled&gt;true&lt;/ssl-enabled&gt;
  9. &lt;/configuration&gt;
  10. &lt;/plugin&gt;

Also tried with "security.require-ssl=true" in application.properties

But both are not redirecting. Any suggestions?

答案1

得分: 1

提供一个位于项目中的 src/main/webapp/WEB-INF/web.xml 文件(如果你正在使用 maven-war-plugin,该文件将被安装到 WEB-INF 目录中),内容类似于:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
  5. http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
  6. version="3.1">
  7. <security-constraint>
  8. <web-resource-collection>
  9. <web-resource-name>HTTPS Redirect</web-resource-name>
  10. <url-pattern>/*</url-pattern>
  11. </web-resource-collection>
  12. <user-data-constraint>
  13. <transport-guarantee>CONFIDENTIAL</transport-guarantee>
  14. </user-data-constraint>
  15. </security-constraint>
  16. </web-app>
英文:

Provide a src/main/webapp/WEB-INF/web.xml (which will be installed into WEB-INF if you're using maven-war-plugin) in your project with something like:

  1. &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  2. &lt;web-app xmlns=&quot;http://xmlns.jcp.org/xml/ns/javaee&quot;
  3. xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
  4. xsi:schemaLocation=&quot;http://xmlns.jcp.org/xml/ns/javaee
  5. http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd&quot;
  6. version=&quot;3.1&quot;&gt;
  7. &lt;security-constraint&gt;
  8. &lt;web-resource-collection&gt;
  9. &lt;web-resource-name&gt;HTTPS Redirect&lt;/web-resource-name&gt;
  10. &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
  11. &lt;/web-resource-collection&gt;
  12. &lt;user-data-constraint&gt;
  13. &lt;transport-guarantee&gt;CONFIDENTIAL&lt;/transport-guarantee&gt;
  14. &lt;/user-data-constraint&gt;
  15. &lt;/security-constraint&gt;
  16. &lt;/web-app&gt;

huangapple
  • 本文由 发表于 2020年9月12日 00:52:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/63851254.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定