保護我的web app安全-爲網頁加入SSL安全證書

本文爲博客—(使用google cloud部署基於flask的網站)的後續部分😎
本文內容的目的使確保到你的服務器的流量是安全的,並使用“Let’s Encrypt”來獲取免費的證書;
下面就是我們的實現部分:
1.升級ubuntu的apt,並且下載一些libraries,否則下一步會出現bug

sudo apt update
sudo apt-get install software-properties-common

2.添加Certbot Ubuntu存儲庫:

sudo add-apt-repository ppa:certbot/certbot

3.安裝Certbot的Nginx軟件包:

sudo apt install python-certbot-nginx

4.Certbot提供了多種通過插件獲取SSL證書的方法。Nginx插件將負責重新配置Nginx並在必要時重新加載配置。要使用此插件,請鍵入以下內容:

sudo certbot --nginx -d your_domain -d www.your_domain

將輸出:

Output
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,然後按Enter如果不想總更換安全信息,選擇1,否則選2
接下來還會有一個選擇,關於暫時的時間長短,選擇1或2再Enter
下面是正常的輸出代碼,恭喜你,你的網站現在安全了!

NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/your_domain/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/your_domain/privkey.pem
   Your cert will expire on 2018-07-23. 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

我們不再需要冗餘HTTP配置文件配置:

sudo ufw delete allow 'Nginx HTTP'

下次訪問,請使用==https://==導航到你的域

https://your_domain

不過,立即查看的時候,小鎖頭沒有立即出現,但是過了5分鐘,再次訪問,你就發現,有小鎖頭了欸!👏
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章