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)统 ...
随机推荐
- Knockout学习之文本和外观绑定器
文本和外观绑定器 “visible”绑定 该绑定主要用来让我们通过监控属性可以控制html文档的显示,只要绑定的监控属性为false.0.null或者undefined则隐藏该标签,否则显示.比如下面 ...
- Python-Flask实现电影系统管理后台
代码地址如下:http://www.demodashi.com/demo/14850.html 项目描述 该项目实现电影系统的后台接口,包括用户,电影,场次,订单,评论,优惠券,推荐,收藏等多个模块, ...
- C语言的经典排序算法源码
1.插入排序:插入法是一种比较直观的排序方法.它首先把数组头两个元素排好序,再依次把后面的元素插入适当的位置.把数组元素插完也就完成了排序.代码如下: #include<stdio.h> ...
- android.database.sqlite.SQLiteException: near "FROM"
07-20 00:19:30.496: E/JavaBinder(6807): *** Uncaught remote exception! (Exceptions are not yet su ...
- ios中通过过RGB绘制图片
+ (UIImage *) ImageWithColor: (UIColor *) color frame:(CGRect)aFrame { aFrame = CGRectMake(, , aFram ...
- DPDK架构与特点(转)
from:http://www.cnblogs.com/mylinuxer/p/4277676.html DPDK架构与特点 当年在某公司实习的时候,当时老大给了我一份DPDK的文档,说是将来很有用, ...
- memcached完全剖析--1. memcached的基础
翻译一篇技术评论社的文章,是讲memcached的连载.fcicq同学说这个东西很有用,希望大家喜欢. 发表日:2008/7/2 作者:长野雅广(Masahiro Nagano) 原文链接:http: ...
- ubuntu源列表(清华,阿里,官方,选一即可)
Ubuntu的源列表在/etc/apt/sources.list中,替换即可 #清华的源deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial m ...
- HDU 1023 Train Problem II (大数卡特兰数)
Train Problem II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- log4j(五)——如何控制不同目的地的日志输出?
一:测试环境与log4j(一)——为什么要使用log4j?一样,这里不再重述 二:老规矩,先来个栗子,然后再聊聊感受 import org.apache.log4j.*; import java.io ...