From 0354a92e839cb5b859b1e362d56d7a078e81407c Mon Sep 17 00:00:00 2001 From: qibaoguang Date: Fri, 10 Apr 2015 00:20:12 +0800 Subject: [PATCH] Update 71.3. Enable HTTPS when running behind a proxy server.md --- ...3. Enable HTTPS when running behind a proxy server.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/IX. ‘How-to’ guides/71.3. Enable HTTPS when running behind a proxy server.md b/IX. ‘How-to’ guides/71.3. Enable HTTPS when running behind a proxy server.md index e69de29..7c6563e 100644 --- a/IX. ‘How-to’ guides/71.3. Enable HTTPS when running behind a proxy server.md +++ b/IX. ‘How-to’ guides/71.3. Enable HTTPS when running behind a proxy server.md @@ -0,0 +1,12 @@ +### 71.3. 当前端使用代理服务器时,启用HTTPS + +对于任何应用来说,确保所有的主端点(URL)都只在HTTPS下可用是个重要的苦差事。如果你使用Tomcat作为servlet容器,那Spring Boot如果发现一些环境设置的话,它将自动添加Tomcat自己的RemoteIpValve,你也可以依赖于HttpServletRequest来报告是否请求是安全的(即使代理服务器的downstream处理真实的SSL终端)。这个标准行为取决于某些请求头是否出现(`x-forwarded-for`和`x-forwarded-proto`),这些请求头的名称都是约定好的,所以对于大多数前端和代理都是有效的。 + +你可以向application.properties添加以下设置里开启该功能,比如: +```yml +server.tomcat.remote_ip_header=x-forwarded-for +server.tomcat.protocol_header=x-forwarded-proto +``` +(这些属性出现一个就会开启该功能,或者你可以通过添加一个TomcatEmbeddedServletContainerFactory bean自己添加RemoteIpValve) + +Spring Security也可以配置成针对所以或某些请求需要一个安全渠道(channel)。想要在一个Spring Boot应用中开启它,你只需将application.properties中的`security.require_ssl`设置为`true`即可。