HTTPS協議取代HTTP已是必然,但是這個過程中成本最高的必然是高昂的數字證書費用。這導致協議的過度存在阻礙,我想這也是部分站長未將網站過渡到HTTPS協議的最大痛點之一。
從HTTP到HTTPS
下面我給廣大的站長們推薦一個免費的證書申領網站——Let’s Encrypt。
地址:https://letsencrypt.org/
Let's Encrypt作為一個公共且免費SSL的項目逐漸被廣大用戶傳播和使用,是由Mozilla、Cisco、Akamai、IdenTrust、EFF等組織人員發起,主要的目的也是為了推進網站從HTTP向HTTPS過度的進程,目前已經有越來越多的商家加入和贊助支持。
Let’s Encrypt上面申請免費的證書,證書有效期為90天,但可以通過再次申請。下面我就來試試好不好用。
申請操作
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 domain.csr
Step3:讓你的網站主機challenge 文件
# 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: 獲得簽名證書!
# 下載acme_tiny.py 這個是github地址https://github.com/diafygi/acme-tiny.git
# Run the/>python acme_tiny.py --account-key ./account.key --csr ./domain.csr --acme-dir /var/www/challenges/ > ./signed_chain.crt
Step5: 安裝證書
配置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;
}
}
注: 以上操作均在linux環境下。
我也是主要參考https://github.com/diafygi/acme-tiny.git這個git項目,在這裡感謝作者。大家如有疑問可以到該git項目下交流。
閱讀更多 CheeseQ 的文章