配置前提:请确保网站已经支持https协议并且所有服务均通过https协议提供。
一、Apache服务器
编辑apache 配置文件:
在/etc/apache2/sites-enabled/website.conf中取消以下内容的注释:
LoadModule headers_module modules/mod_headers.so
在/etc/apache2/httpd.conf增加以下内容至应用的 HTTPS VirtualHost中
Header always Strict-Transport-Security "max-age=63072000; includeSubdomains; preload"
二、Nginx服务器
编辑 Nginx 配置文件(如:/usr/local/nginx/conf/nginx.conf),将下面行添加到你的应用配置的server 块中。
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload"
三、Lighttpd服务器
将下述配置增加到Lighttpd 配置文件,一般在/etc/lighttpd/lighttpd.conf。
server.modules += ( “mod_setenv” )
$HTTP[“scheme”] == “https” {
setenv.add-response-header = (“Strict-Transport-Security” => “max-age=63072000; includeSubdomains; preload”)
}