302跳转

通常情况下,我们将用户的 HTTP 请求 302 跳转到 HTTPS,这会存在两个问题:

  1. 不够安全,302 跳转会暴露用户访问站点,也容易被劫持
  2. 拖慢访问速度,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的更多相关文章

  1. [转]三大WEB服务器对比分析(apache ,lighttpd,nginx)

    原博文地址:http://www.blogjava.net/daniel-tu/archive/2008/12/29/248883.html 一.软件介绍(apache  lighttpd  ngin ...

  2. 三大WEB服务器对比分析(apache ,lighttpd,nginx)

    一.软件介绍(apache  lighttpd  nginx) 1. lighttpd Lighttpd是一个具有非常低的内存开销,cpu占用率低,效能好,以及丰富的模块等特点.lighttpd是众多 ...

  3. 软件介绍(apache lighttpd nginx)

    一.软件介绍(apache  lighttpd  nginx) 1. lighttpd Lighttpd是一个具有非常低的内存开销,cpu占用率低,效能好,以及丰富的模块等特点.lighttpd是众多 ...

  4. 一.软件介绍(apache lighttpd nginx)

    一.软件介绍(apache  lighttpd  nginx) 1. lighttpd Lighttpd是一个具有非常低的内存开销,cpu占用率低,效能好,以及丰富的模块等特点.lighttpd是众多 ...

  5. 转: 三大WEB服务器对比分析(apache ,lighttpd,nginx) (2008年的旧文,仅供参考之用)

    from:  http://www.blogjava.net/daniel-tu/archive/2008/12/29/248883.html 三大WEB服务器对比分析(apache ,lighttp ...

  6. (转)三大WEB服务器对比分析(apache ,lighttpd,nginx)

    ref : https://www.iteye.com/blog/hai0378-1860220   一.软件介绍(apache  lighttpd  nginx) 1. lighttpd Light ...

  7. Apache、nginx 、lighttpd性能比较

    Apache.nginx .lighttpd性能比较 1. web服务器简介 1. lighttpd Lighttpd是一个德国人领导的开源软件,其根本的目的是提供一个专门针对高性能网站,安全.快速. ...

  8. linux后台server开发环境的部署配置和验证(nginx+apache+php-fpm+FASTCGI(C/C++))

    linux后台server开发环境部署配置 引言 背景 随着互联网业务的不断增多.开发环境变得越来越复杂,为了便于统一server端的开发部署环境,特制定本配置文档. 使用软件 CentOS 6.3( ...

  9. (转)Nginx/Apache服务连接数梳理

    Nginx/Apache服务连接数梳理 原文:http://www.cnblogs.com/kevingrace/p/6211542.html 统计连接数,使用netstat命令或ss命令都可以1)统 ...

随机推荐

  1. SpringBoot之actuator

    在springBoot中集成actuator可以很方便的管理和监控应用的状态. 暴露的Restful接口有: HTTP方法 路径 描述 鉴权 GET /autoconfig 查看自动配置的使用情况 t ...

  2. Axure 实现批量的勾选和反选

    百度网盘:http://pan.baidu.com/s/1gf4RR2b 1.如何实现批量的勾选和反选的操作? 2.步骤 1)创建3个复选框.2个按钮(全选/反选) 2)设置全选按钮点击事件——选中“ ...

  3. Ceontos6.X配置XDMCP远程调用图形化

    Linux一般不需要图形化,但是偶尔也是需要的,基于X11协议的图形化XDMCP很受推广,VNC也是很不错的... 前提: 关闭防火墙,不关闭需要配置177端口放行 关闭selinux,不关闭自己配置 ...

  4. Centos6.x 设置终端超时, 加强用户密码策略

    1. 密码有效期, 密码长度 $ more /etc/login.defs # Password aging controls: # # PASS_MAX_DAYS Maximum number of ...

  5. sort.js

    JavaScript to achieve the ten common sorting algorithm library 1 ; (function (global, factory) { // ...

  6. jquery.uploadify 在firefox会出现httperror

    原来是因为我的上传处理页面的page 继承了一个基类影响到的 然后这个基类 好像是因为在别的项目里面的原因 希望对也遇到这样的问题的人有帮助咯

  7. numpy中的argpartition

    numpy.argpartition(a, kth, axis=-1, kind='introselect', order=None) 在快排算法中,有一个典型的操作:partition.这个操作指: ...

  8. 【C++】atoi与stoi

    stoi函数默认要求输入的参数字符串是符合int范围的[-2147483648, 2147483647],否则会runtime error.atoi函数则不做范围检查,若超过int范围,则显示-214 ...

  9. 【Android】Android屏幕状态操作

    目录结构: contents structure [+] 如何监听屏幕锁屏 如何实现手机屏幕在锁屏后继续运行 最近笔者在做一个功能,就是实现Android程序在锁屏后可以继续运行,笔者在网上查了一些资 ...

  10. Swift 对象

    1.对象 对象是类的具体化的东西,从抽象整体中具体化出的特定个体. 对象是一个动态的概念. 每一个对象都存在着有别于其他对象的属于自己的独特属性和行为. 对象的属性可以随着他自己的行为的变化而改变. ...