轉載地址:https://www.52chenqi.cn/?p=29python
HTTPS(全稱:Hyper Text Transfer Protocol over Secure Socket Layer),是以安全爲目標的HTTP通道,簡單講是HTTP的安全版。即HTTP下加入SSL層,HTTPS的安全基礎是SSL,所以加密的詳細內容就須要SSL。 它是一個URI scheme(抽象標識符體系),句法類同http體系。用於安全的HTTP數據傳輸。https:URL代表它使用了HTTP,但HTTPS存在不一樣於HTTP的默認端口及一個加密/身份驗證層(在HTTP與TCP之間)。這個系統的最初研發由網景公司(Netscape)進行,並內置於其瀏覽器Netscape Navigator中,提供了身份驗證與加密通信方法。如今它被普遍用於萬維網上安全敏感的通信,例如交易支付方面。nginx
原理就不講了,主要講一下如何把咱們的網站變成https以及https的有點。git
1、從HTTP到HTTPSgithub
我這裏是到Let’s Encrypt上面申請免費的證書,他的證書有效期爲90天,但能夠經過再次申請。下面我就來試試好很差用。web
Step1: 建立Let’s Encrypt帳戶私鑰openssl genrsa 4096 > account.key
瀏覽器
Step2: 爲您的域建立證書籤名請求(CSR)安全
# Generate a domain private key (if you haven't already) openssl genrsa 4096 > domain.key # For a single domain 單域名 openssl req -new -sha256 -key domain.key -subj "/CN=yoursite.com" > domain.csr # For multiple domains 多域名 (use this one if you want both www.yoursite.com and yoursite.com) openssl req -new -sha256 -key domain.key -subj "/" -reqexts SAN -config <(cat /etc/ssl/openssl.cnf <(printf "[SAN]\nsubjectAltName=DNS:yoursite.com,DNS:www.yoursite.com")) > domain.csr
Step3:讓你的網站主機challenge 文件session
# Make some challenge folder (modify to suit your needs) mkdir -p /var/www/challenges/
# Example for nginxserver { listen 80; server_name yoursite.com www.yoursite.com; location /.well-known/acme-challenge/ { alias /var/www/challenges/; try_files $uri =404; } ...the rest of your config }
Step4: 得到簽名證書!dom
# 下載acme_tiny.py 這個是github地址https://github.com/diafygi/acme-tiny.git
# Run the script on your server python acme_tiny.py --account-key ./account.key --csr ./domain.csr --acme-dir /var/www/challenges/ > ./signed_chain.crt
Step5: 安裝證書ide
配置nginx.conf
server { listen 443 ssl; server_name yoursite.com, www.yoursite.com; ssl_certificate /path/to/signed_chain.crt; ssl_certificate_key /path/to/domain.key; ssl_session_timeout 5m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA; ssl_session_cache shared:SSL:50m; ssl_dhparam /path/to/server.dhparam; ssl_prefer_server_ciphers on; ...the rest of your config }server { listen 80; server_name yoursite.com, www.yoursite.com; location /.well-known/acme-challenge/ { alias /var/www/challenges/; try_files $uri =404; } ...the rest of your config }
http自動跳轉到https
server { listen 80; server_name www.52chenqi.cn 52chenqi.cn; location /.well-known/acme-challenge/ { root /usr/local/nginx/ssl/www/; try_files $uri =404; } location / { rewrite ^(.*) https://$server_name$1 permanent; } }
2、優勢
一、HTTPS具備更好的加密性能,避免用戶信息泄露;
二、HTTPS複雜的傳輸方式,下降網站被劫持的風險;
三、搜索引擎已經全面支持HTTPS抓取、收錄,而且會優先展現HTTPS結果;
四、HTTPS綠鎖表示能夠提高用戶對網站信任程度;
五、能夠有效防止山寨、鏡像網站等