HTTPS就等于HTTP加上TLS(SSL),HTTPS协议的目标主要有三个:php
数据保密性。保证内容在传输过程当中不会被第三方查看到。就像快递员传递包裹时都进行了封装,别人没法知道里面装了什么东西。
数据完整性。及时发现被第三方篡改的传输内容。就像快递员虽然不知道包裹里装了什么东西,但他有可能中途掉包,数据完整性就是指若是被掉包,咱们能轻松发现并拒收。
身份校验。保证数据到达用户指望的目的地。就像咱们邮寄包裹时,虽然是一个封装好的未掉包的包裹,但必须肯定这个包裹不会送错地方。html
StartSSL免费SSL证书申请和帐户注册完整过程
新StartSSL免费SSL证书申请使用:Apache和Ngnix安装配置SSL证书
Nginx下配置网站ssl实现https访问
HTTPS介绍nginx
申请的过程能够看上边的第一篇博文,申请后最终会须要两个文件,一个扩展名为.crt,一个扩展名为.key文件,而后经过命令将其传入nginx服务器的目录下:web
➜ ~ pwd /Users/corwien // 将本地文件上传到服务器的/home/目录下先 scp /Users/corwien/ssl/ssl.domain—name.cn.crt root@120.23.12.5:/home/ scp /Users/corwien/ssl/ssl.domain-name.cn.key root@120.23.12.5:/home/
vim /etc/nginx/sites-available/default
下面是我添加SSL后的配置文件,须要的能够参考:apache
server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; root /var/www/your-project/public; index index.php index.html index.htm; # Make site accessible from http://localhost/ server_name your-domain.cn; # SSL重写指向下面的HTTPS的443端口-20160924 rewrite ^/(.*) https://your-domain.cn/$1 permanent; location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ /index.php?$query_string; # Uncomment to enable naxsi on this location } location ~ \.php$ { try_files $uri /index.php =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } # HTTPS server # server { listen 443; server_name your-domain.cn; # root /var/www/your-domain/public; index index.php index.html index.htm; # SSL 配置 ssl on; ssl_certificate /home/ssl.your-domain.cn.crt; ssl_certificate_key /home/ssl.your-domain.cn.key; # ssl_session_timeout 5m; # # ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2; # ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES"; # ssl_prefer_server_ciphers on; # location / { try_files $uri $uri/ /index.php?$query_string; } location ~ \.php$ { try_files $uri /index.php =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
service nginx restart
这时会出现这样的提示,让你输入你的SSL证书的密码(就是你生成cer那一步的密码,可别忘记了)vim
* Restarting nginx nginx Enter PEM pass phrase: your_ssl_password(输入你的密码) Enter PEM pass phrase: your_ssl_password(输入你的密码) [ OK ]
在浏览器输入你的网站域名:浏览器
https://your-domian.cn
OK ,若是不出意外,你的SSL配置成功了!安全
既然HTTPS很是安全,数字证书费用也不高,那为何互联网公司不所有使用HTTPS呢?缘由主要有两点:
HTTPS对速度的影响很是明显。每一个HTTPS链接通常会增长1-3个RTT,加上加解密对性能的消耗,延时还有可能再增长几十毫秒。
HTTPS对CPU计算能力的消耗很严重,彻底握手时,web server的处理能力会下降至HTTP的10%甚至如下。
HTTPS为何会严重下降性能?主要是握手阶段时的大数运算。其中最消耗性能的又是密钥交换时的私钥解密阶段(函数是rsa_private_decryption)。这个阶段的性能消耗占整个SSL握手性能消耗的95%。
然而随着各大网站的相继跟进与硬件的摩尔定律下,为了安全而作这点性能牺牲仍是值得的。服务器