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

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

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>'选项

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

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

英文:

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

&lt;plugin&gt;
    &lt;groupId&gt;com.google.cloud.tools&lt;/groupId&gt;
    &lt;artifactId&gt;appengine-maven-plugin&lt;/artifactId&gt;
    &lt;version&gt;2.2.0&lt;/version&gt;
    &lt;configuration&gt;
        &lt;projectId&gt;sample-spring-boot&lt;/projectId&gt;
        &lt;version&gt;1&lt;/version&gt;
        &lt;ssl-enabled&gt;true&lt;/ssl-enabled&gt;
    &lt;/configuration&gt;
&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 目录中),内容类似于:

<?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>
英文:

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:

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

确定