原文來自 https://www.codecasts.com/blo...python
Let's Encrypt 的服務相信不少人都知道了,我我的認爲這是最好的免費 SSL 服務。下面內容即便如何在本身的網站上使用 Let's Encrypt 實現 SSL.nginx
注意若是你的域名沒備案,在購買主機的時候,推薦你們購買騰訊雲或者阿里雲境外的主機。
Certbot 其實就是維護 Let's Encrypt 的 Package,在 Ubuntu 16.04 上,咱們能夠這樣安裝:web
首先安裝 Nginx:ubuntu
sudo apt-get install nginx
以上過程,等待安裝完畢就好。服務器
而後添加 package repositoryapp
sudo add-apt-repository ppa:certbot/certbot
這個過程當中,等待驗證完畢,按下 ENTER
就好。而後更新 apt 源數據:dom
sudo apt-get update
最後,安裝 Certbot 的 Nginx package:編輯器
sudo apt-get install python-certbot-nginx
安裝完 Nginx 和 Certbot 以後,須要簡單配置 Nginx 以便於 Let's Encrypt 能起做用:ide
sudo vi /etc/nginx/sites-available/default
使用 vi 編輯器打開 /etc/nginx/sites-available/default
,能夠直接刪除裏面的全部內容,而後再添加下面的配置:post
server { listen 80; listen [::]:80; server_name your-domain.com www.your-domain.com; }
注意這裏的
your-domain.com
換成你本身的域名。
保存退出以後,執行如下命令來檢測 Nginx 的配置文件是否有錯:
sudo nginx -t
若是出現相似 syntax ok 這樣的語句,就說明 Nginx 的配置文件沒有問題。以後就是從新加載 Nginx 的配置文件了:
sudo service nginx reload
前面的兩大步配置完成,就可使用 Let's Encrypt 簽發 SSL 證書了:
sudo certbot --nginx -d your-domian.com -d www.your-domain.com
注意這裏的
your-domain.com
換成你本身的域名。
若是你第一次運行 certbot
命令的話,你須要在彈出的窗口輸入你的郵箱地址還有須要接受 Let's Encrypt 的協議,這樣以後,你大概會看到下面的文字:
Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access. ------------------------------------------------------------------------------- 1: No redirect - Make no further changes to the webserver configuration. 2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for new sites, or if you're confident your site works on HTTPS. You can undo this change by editing your web server's configuration. ------------------------------------------------------------------------------- Select the appropriate number [1-2] then [enter] (press 'c' to cancel):
在上面這裏選擇 1
或者 2
,我推薦你們直接選擇 2
,由於這個會直接將你的 nginx 文件配置好而且是會將 http 跳轉到 https 的。
選擇完畢以後,等待 SSL 生成完畢,就會有相似這樣的輸出:
IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at /etc/letsencrypt/live/your-domain.com/fullchain.pem. Your cert will expire on 2017-12-29. To obtain a new or tweaked version of this certificate in the future, simply run certbot again with the "certonly" option. To non-interactively renew *all* of your certificates, run "certbot renew" - Your account credentials have been saved in your Certbot configuration directory at /etc/letsencrypt. You should make a secure backup of this folder now. This configuration directory will also contain certificates and private keys obtained by Certbot so making regular backups of this folder is ideal. - If you like Certbot, please consider supporting our work by: Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate Donating to EFF: https://eff.org/donate-le
而後在上面的文字中,這個 /etc/letsencrypt/live/your-domain.com/fullchain.pem
路徑很重要,就是你的 SSL 證書路徑。
其實到這裏,訪問
your-domain.com
應該就能夠看到 https 的效果了。
由於 Let's Encrypt 簽發的 SSL 證書有效期只有 90 天,全部在過時以前,咱們須要自動更新 SSL 證書,而若是你使用最新的 certbot
的話,Let's Encrypt 會幫你添加自動更新的腳本到 /etc/cron.d
裏,你只須要去檢測一下這個命令是否生效就OK!
sudo certbot renew --dry-run
若是這個命令你沒看到什麼 error 的話,那就是沒什麼問題了。
本文主要是介紹了在 Ubuntu 16.04 的雲服務器上,使用 Nginx 做爲服務器軟件狀況下,如何配置 Let's Encrypt 的 SSL 證書,使得網站得以支持 https
的過程。內容很淺,可是我以爲仍是挺有用的。