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%。
然而隨着各大網站的相繼跟進與硬件的摩爾定律下,爲了安全而作這點性能犧牲仍是值得的。服務器