之前寫過利用 wordpress 搭建的一個博客『我的博客搭建( wordpress )』,綁定了域名,可是沒開啓 https,在瀏覽博客的時候瀏覽器會提示不安全。下面來談下我的博客如何免費申請證書,開啓 https 。python
系統環境要求:python2.7+
手動申請網址:letsencrypt.osfipin.com/v2/login
yum install -y git
查看版本號:git --version
卸載:yum remove git
git clone https://github.com/letsencrypt/letsencrypt
在 letsencrypt 目錄下執行nginx
./letsencrypt-auto certonly --standalone --email YOUR_EMAIL -d xxx.com --quiet --agree-tos
rm -rf ~/.pip/pip.conf
# vim /etc/nginx/nginx.conf ... http { ... server { listen 80; server_name xxx.com; return 301 https://$host$request_uri; } server { listen 443 ssl http2; server_name xxx.com; server_name_in_redirect off; ssl_certificate "/etc/letsencrypt/live/hirat.online/fullchain.pem"; ssl_certificate_key "/etc/letsencrypt/live/hirat.online/privkey.pem"; location / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header REQUEST-URI $request_uri; proxy_set_header Cookie $http_cookie; proxy_pass http://localhost:9090; proxy_cookie_domain domino.server nginx.server; proxy_redirect off; } } }
systemctl start nginx.service
瀏覽器輸入:https://xxx.com 看看效果。git
特別提醒:上面的方法申請的 Let's Encrypt 免費證書有效期90天的,別忘了續簽。