發(fā)表日期:2018-12 文章編輯:小燈 瀏覽次數(shù):4980
總覺得寫個(gè)文章應(yīng)該有個(gè)起承轉(zhuǎn)合是吧,那就講一下起因吧,老夫發(fā)現(xiàn)postman不能測試接口了。。。好吧我選擇了最麻煩的一個(gè)解決方法,也算是閑的蛋疼。
正文
第一步當(dāng)然是下載安裝
$ wgethttps://dl.eff.org/certbot-auto$ chmod a+x ./certbot-auto$ ./certbot-auto
這個(gè)小工具會自動下載并安裝相關(guān)依賴和 Python 包。稍等一下就完成了。
第二部生成證書
生成證書過程中需要鑒權(quán)。有多種方式,比如webroot、standalone、apache、nginx、manual等。我使用過前兩種。 這兩種中,簡單一點(diǎn)的是standalone。不過,這種方式需要把現(xiàn)有的 WebServer 停掉,因?yàn)檫@種方式下 certbot 需要占用 80 端口。
# ./certbot-auto certonly --text --agree-tos --email webmaster@example.com --standalone -d example.com -d www.example.com -d service.example.com
-d參數(shù)指定域名,可多個(gè)。一般第一個(gè)是主域名。
webroot方式稍微繁瑣一些,但好處是不需要關(guān)?,F(xiàn)有的 WebServer 。此方法需要在域名對應(yīng)的根目錄下新建.well-known目錄并寫入若干文件供驗(yàn)證服務(wù)訪問。 因此需要配置 WebServer 允許外部訪問http://example.com/.well-known路徑。配置方法請參考相應(yīng) WebServer 的文檔。Nginx 的默認(rèn)配置應(yīng)該不用修改,Apache 就不知道了。 另外,不同的域名的根路徑可能不同,下面的例子中可以看到為不同的域名指定不同的根路徑。
# ./certbot-auto certonly --text --agree-tos --email webmaster@excample.com --webroot -w /var/www/example -d example.com -d www.example.com -w /var/service/example -d service.ulefa.com
無論使用那種方式,運(yùn)行以上命令后都會在/etc/letsencrypt生成一堆東西,包括證書。
第三步修改Nginx 配置以提供 HTTPS 服務(wù)
打開 Nginx 的配置文件(默認(rèn)為:/etc/nginx/nginx.conf),在需要提供 HTTPS 的server下新增以下三行,并把listen 80;刪掉:
ssl_certificate /etc/letsencrypt/live/api.bqtabc.adflash.cn/fullchain.pem;ssl_certificate_key/etc/letsencrypt/live/api.bqtabc.adflash.cn/privkey.pem;ssl_session_timeout 5m;ssl_protocols SSLv2 SSLv3 TLSv1;ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;ssl_prefer_server_ciphers on;
新增以下server使所有 HTTP 請求都跳轉(zhuǎn)至 HTTPS :
server {listen80;server_name example.com www.example.com service.example.com;return301 https://$host$request_uri;}
最后定期 renew
Let's Encrypt 的證書有效期為 90 天,所以需要在到期前 renew 一下證書。 使用以下命令即可。
# ./certbot-auto renew --text --agree-tos --email webmaster@excample.com --webroot -w /var/www/example -d example.com -d www.example.com -w /var/service/example -d service.ulefa.com
或者直接運(yùn)行以下命令,此時(shí) certbot 會使用默認(rèn)參數(shù)(此例為:/etc/letsencrypt/renewal/example.com.conf):
# ./certbot-auto renew
又或者在crontab里加入定時(shí)任務(wù),每隔 80 天的凌晨 4 點(diǎn)執(zhí)行一次 renew:
04 */80 * * /path/to/certbot-auto renew &>> /dev/null
日期:2018-04 瀏覽次數(shù):6883
日期:2017-02 瀏覽次數(shù):3565
日期:2017-09 瀏覽次數(shù):3815
日期:2017-12 瀏覽次數(shù):3640
日期:2018-12 瀏覽次數(shù):4979
日期:2016-12 瀏覽次數(shù):4708
日期:2017-07 瀏覽次數(shù):13758
日期:2017-12 瀏覽次數(shù):3630
日期:2018-06 瀏覽次數(shù):4385
日期:2018-05 瀏覽次數(shù):4567
日期:2017-12 瀏覽次數(shù):3676
日期:2017-06 瀏覽次數(shù):4094
日期:2018-01 瀏覽次數(shù):4070
日期:2016-12 瀏覽次數(shù):4029
日期:2018-08 瀏覽次數(shù):4531
日期:2017-12 瀏覽次數(shù):3860
日期:2016-09 瀏覽次數(shù):6615
日期:2018-07 瀏覽次數(shù):3322
日期:2016-12 瀏覽次數(shù):3343
日期:2018-10 瀏覽次數(shù):3492
日期:2018-10 瀏覽次數(shù):3602
日期:2018-09 瀏覽次數(shù):3691
日期:2018-02 瀏覽次數(shù):3715
日期:2015-05 瀏覽次數(shù):3637
日期:2018-09 瀏覽次數(shù):3416
日期:2018-06 瀏覽次數(shù):3543
日期:2017-02 瀏覽次數(shù):3981
日期:2018-02 瀏覽次數(shù):4453
日期:2018-02 瀏覽次數(shù):4323
日期:2016-12 瀏覽次數(shù):3683
Copyright ? 2013-2018 Tadeng NetWork Technology Co., LTD. All Rights Reserved.