【问题标题】:Spring boot application http to https redirect in Google App Engine谷歌 App Engine 中的 Spring Boot 应用程序 http 到 https 重定向
【发布时间】:2020-09-11 16:52:31
【问题描述】:

我有一个 Spring Boot 应用程序(2.3.0 版)并成功托管在 Google App Engine 标准环境中并且工作正常。此门户有自己的 Google 管理的 SSL 证书。

如何将门户从 http 重定向到 https。

我已尝试使用 pom.xml

中的 'true' 选项
<plugin>
    <groupId>com.google.cloud.tools</groupId>
    <artifactId>appengine-maven-plugin</artifactId>
    <version>2.2.0</version>
    <configuration>
        <projectId>sample-spring-boot</projectId>
        <version>1</version>
        <ssl-enabled>true</ssl-enabled>
    </configuration>
</plugin>

还尝试在 application.properties

中使用“security.require-ssl=true

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

【问题讨论】:

    标签: java spring-boot google-app-engine


    【解决方案1】:

    在您的项目中提供src/main/webapp/WEB-INF/web.xml(如果您使用的是maven-war-plugin,它将被安装到WEB-INF),例如:

    <?xml version="1.0" encoding="utf-8"?>                                                                                                                                                                                    
    <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"                                                                                                                                                                                    
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"                                                                                                                                                                         
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee                                                                                                                                                                        
                                 http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"                                                                                                                                                       
                                 version="3.1">                                                                                                                                                                                            
      <security-constraint>                                                                                                                                                                                                                
        <web-resource-collection>                                                                                                                                                                                                          
          <web-resource-name>HTTPS Redirect</web-resource-name>                                                                                                                                                                            
          <url-pattern>/*</url-pattern>                                                                                                                                                                                                    
        </web-resource-collection>                                                                                                                                                                                                         
        <user-data-constraint>                                                                                                                                                                                                             
          <transport-guarantee>CONFIDENTIAL</transport-guarantee>                                                                                                                                                                          
        </user-data-constraint>                                                                                                                                                                                                            
      </security-constraint>                                                                                                                                                                                                               
    </web-app>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-04
      • 2014-12-26
      • 2019-05-15
      • 2018-03-10
      • 2016-09-05
      • 2016-07-11
      • 2021-12-12
      相关资源
      最近更新 更多