ThinkSSL🔒 一键申购 5分钟快速签发 30天无理由退款 购买更放心 广告
[TOC] ## 申请证书 ## 配置证书 * [证书配置文件生成器](https://mozilla.github.io/server-side-tls/ssl-config-generator/),by Mozilla * [配置文件模板](https://github.com/SSLMate/tlsconfigguide/tree/master/templates),by SSLMate ## 修改链接 ``` // bad <script src="http://foo.com/jquery.js"></script> // good <!-- 改法一 --> <script src="https://foo.com/jquery.js"></script> <!-- 改法二:推荐,强制该为https --> <script src="//foo.com/jquery.js"></script> ``` ## 301重定向 nginx ``` server { listen 80; server_name domain.com www.domain.com; return 301 https://domain.com$request_uri; } ``` Apache 的写法(.htaccess文件)。 ``` RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] ``` ## 安全措施 ### HTTP严格传输安全(HSTS) - 是强制浏览器只能发出`HTTPS`请求,并阻止用户接受不安全的证书 - 该方法的主要不足是,用户首次访问网站发出HTTP请求时,是不受HSTS保护的 网站的响应头里面,加入一个强制性声明 ``` Strict-Transport-Security: max-age=31536000; includeSubDomains ``` 这段头信息有两个作用 1. 在接下来的一年(即31536000秒)中,浏览器只要向example.com或其子域名发送HTTP请求时,必须采用HTTPS来发起连接。用户点击超链接或在地址栏输入http://www.example.com/,浏览器应当自动将http转写成https,然后直接向https://www.example.com/发送请求。 2. 在接下来的一年中,如果example.com服务器发送的证书无效,用户不能忽略浏览器警告,将无法继续访问该网站。 ### Cookie 网站响应头里面,Set-Cookie字段加上Secure标志即可 ``` Set-Cookie: LSID=DQAAAK...Eaem_vYg; Secure ``` ### 分析网站的安全程度 可以使用 Mozilla 的[Observatory](https://observatory.mozilla.org/)