简体   繁体   English

Google App Engine 中的 Spring 启动应用程序 http 到 https 重定向

[英]Spring boot application http to https redirect in Google App Engine

I have a spring boot application (version 2.3.0) & successfully hosted in Google App Engine standard environment & working fine.我有一个 Spring Boot 应用程序(版本 2.3.0)并成功托管在 Google App Engine 标准环境中并且工作正常。 This portal has its own Google managed SSL certificate.此门户有自己的 Google 管理的 SSL 证书。

How to redirect the portal from http to https.如何将门户从 http 重定向到 https。

I have tried with the ' <ssl-enabled>true</ssl-enabled> ' option in pom.xml我已经尝试在pom.xml 中使用 ' <ssl-enabled>true</ssl-enabled> ' 选项

<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>

Also tried with " security.require-ssl=true " in application.properties还尝试在application.properties 中使用“ security.require-ssl=true

But both are not redirecting.但两者都没有重定向。 Any suggestions?有什么建议?

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:在您的项目中提供一个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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM