nginx、Apache、Lighttpd启用HSTS
302跳转
通常情况下,我们将用户的 HTTP 请求 302 跳转到 HTTPS,这会存在两个问题:
- 不够安全,302 跳转会暴露用户访问站点,也容易被劫持
- 拖慢访问速度,302 跳转需要一个 RTT(The role of packet loss and round-trip time),浏览器执行跳转也需要时间
HSTS
302 跳转是由浏览器触发的,服务器无法完全控制,这个需求导致了 HSTS(HTTP Strict Transport Security)的诞生。HTSP 就是添加 header 头(add_header Strict-Transport-Security max-age=15768000;includeSubDomains),告诉浏览器网站使用 HTTPS 访问,支持HSTS的浏览器(Chrome, firefox, ie 都支持了 HSTS(http://caniuse.com/#feat=stricttransportsecurity))就会在后面的请求中直接切换到 HTTPS。在 Chrome 中会看到浏览器自己会有个 307 Internal Redirect 的内部重定向。在一段时间内也就是max-age定义的时间,不管用户输入www.ttlsa.com还是http://www.ttlsa.com,都会默认将请求内部跳转到https://www.ttlsa.com。
服务器端配置HSTS,减少302跳转,其实HSTS的最大作用是防止302 HTTP劫持。HSTS的缺点是浏览器支持率不高,另外配置HSTS后HTTPS很难实时降级成HTTP。
同时,也建议启用SPDY来提高性能。有关SPDY内容参见前面文章,不在此外累述了。
下面来说说如何在Apache2, NGINX , Lighttpd启用HSTS。
Apache2
|
1
2
3
4
5
6
|
# Optionally load the headers module:
LoadModule headers_module modules/mod_headers.so
<VirtualHost 0.0.0.0:443>
Header always set Strict-Transport-Security "max-age=63072000; includeSubdomains; preload"
</VirtualHost>
|
然后,重启Apache服务。
nginx
|
1
|
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";
|
在server端添加该头部,并重启服务。
Lighttpd
|
1
2
3
4
|
server.modules += ( "mod_setenv" )
$HTTP["scheme"] == "https" {
setenv.add-response-header = ( "Strict-Transport-Security" => "max-age=63072000; includeSubdomains; preload")
}
|
X-Frame-Options 头部
X-Frame-Options 头部添加到HTTPS站点,确保不会嵌入到frame 或 iframe,避免点击劫持,以确保网站的内容不会嵌入到其他网站。
Apache
|
1
|
Header always set X-Frame-Options DENY
|
nginx
|
1
|
add_header X-Frame-Options "DENY";
|
Lighttpd
|
1
2
3
4
|
server.modules += ( "mod_setenv" )
$HTTP["scheme"] == "https" {
setenv.add-response-header = ( "X-Frame-Options" => "DENY")
}
|
nginx、Apache、Lighttpd启用HSTS的更多相关文章
- [转]三大WEB服务器对比分析(apache ,lighttpd,nginx)
原博文地址:http://www.blogjava.net/daniel-tu/archive/2008/12/29/248883.html 一.软件介绍(apache lighttpd ngin ...
- 三大WEB服务器对比分析(apache ,lighttpd,nginx)
一.软件介绍(apache lighttpd nginx) 1. lighttpd Lighttpd是一个具有非常低的内存开销,cpu占用率低,效能好,以及丰富的模块等特点.lighttpd是众多 ...
- 软件介绍(apache lighttpd nginx)
一.软件介绍(apache lighttpd nginx) 1. lighttpd Lighttpd是一个具有非常低的内存开销,cpu占用率低,效能好,以及丰富的模块等特点.lighttpd是众多 ...
- 一.软件介绍(apache lighttpd nginx)
一.软件介绍(apache lighttpd nginx) 1. lighttpd Lighttpd是一个具有非常低的内存开销,cpu占用率低,效能好,以及丰富的模块等特点.lighttpd是众多 ...
- 转: 三大WEB服务器对比分析(apache ,lighttpd,nginx) (2008年的旧文,仅供参考之用)
from: http://www.blogjava.net/daniel-tu/archive/2008/12/29/248883.html 三大WEB服务器对比分析(apache ,lighttp ...
- (转)三大WEB服务器对比分析(apache ,lighttpd,nginx)
ref : https://www.iteye.com/blog/hai0378-1860220 一.软件介绍(apache lighttpd nginx) 1. lighttpd Light ...
- Apache、nginx 、lighttpd性能比较
Apache.nginx .lighttpd性能比较 1. web服务器简介 1. lighttpd Lighttpd是一个德国人领导的开源软件,其根本的目的是提供一个专门针对高性能网站,安全.快速. ...
- linux后台server开发环境的部署配置和验证(nginx+apache+php-fpm+FASTCGI(C/C++))
linux后台server开发环境部署配置 引言 背景 随着互联网业务的不断增多.开发环境变得越来越复杂,为了便于统一server端的开发部署环境,特制定本配置文档. 使用软件 CentOS 6.3( ...
- (转)Nginx/Apache服务连接数梳理
Nginx/Apache服务连接数梳理 原文:http://www.cnblogs.com/kevingrace/p/6211542.html 统计连接数,使用netstat命令或ss命令都可以1)统 ...
随机推荐
- django生成文件txt、pdf(在生成 PDF 文件之前,需要安装 ReportLab 库)
from django.http import HttpResponse def download_file(request): # Text file #response = HttpRespons ...
- Python yield 使用
老是看到好的文章,不由自主的收集过来. 原文链接:https://www.ibm.com/developerworks/cn/opensource/os-cn-python-yield/ 廖大写的, ...
- 基于git 客户端使用shell工具
1 定义全局启动 命令别名 C:\Program Files\Git\etc\profile.d\aliases.sh alias ls='ls -F --color=auto --show-cont ...
- macbook上安装homestead
参考资料: 1:https://solarhell.com/post/2016/04/homestead 2:https://phphub.org/topics/491 3:http://larave ...
- Safari导入书签
1.打开Safari 这边safari会自动带出一些关联的浏览器,但如果你要导入的浏览器不在这里的话,就需要看第二步. 2.比如,这里我要从QQ浏览器导入,先打开QQ浏览器. 其他浏览器都类似,找到书 ...
- LUA可变长参数 ... 三个点
本文翻译自 LUA官方文档 When a function is called, the list of arguments is adjusted to the length of the list ...
- 树莓派进阶之路 (012) - 树莓派配置文档 config.txt 说明
原文连接:http://elinux.org/RPi_config.txt 由于树莓派并没有传统意义上的BIOS, 所以现在各种系统配置参数通常被存在”config.txt”这个文本文件中. 树莓派的 ...
- ROS学习(五)—— 编译ROS Package
提前准备: 记得事先source你的环境配置(setup)文件,在Ubuntu中的操作指令如下. source /opt/ros/kinetic/setup.bash 一.使用catkin_make ...
- FluentValidation:C#后端输入验证框架的官方文档解读
参照 FluentValidation 的官方文档写的例子,方便日后查看和使用. 原文:https://github.com/JeremySkinner/FluentValidation/wiki H ...
- VS2017 IDE开发工具选型、安装和使用
原文地址:https://blog.csdn.net/boonya/article/details/78739500 距离上次使用VS工具已是2年前了,这次准备选择比较新的版本来开发桌面程序了.总的来 ...