英文:
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 '<ssl-enabled>true</ssl-enabled>' option in pom.xml
<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
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:
<?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>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论