如今已經有不少的免費ssl證書提供商,國內的也有,nginx
不過國內政策要求還要把key給他們,git
咱們仍是用Let’s Encrypt吧。github
這裏有官方中文文檔 ->biubiubiuweb
官方推薦的是使用Certbot ACME 客戶端shell
可是這裏用的是acme.shapache
acme.sh是個開源的shell腳本,要更爲輕量,對於個人破爛vps仍是選擇輕量點的吧。dom
Acme.sh也有中文的簡單教程,很詳細:-(´▽`)-
curl
Acme.sh會在天天 0:00 點自動檢測全部的證書,須要更新時會自動更新post
acme全部東西都在~/.acme.sh/
下面,不會對外形成影響優化
curl https://get.acme.sh | sh
能夠設置別名,否則命令太長了alias acme.sh=~/.acme.sh/acme.sh
能夠本身設置
acme.sh --issue -d mydomain.com -d www.mydomain.com --webroot /home/wwwroot/mydomain.com/
nginx/apache能夠自動獲取域名
acme.sh --issue -d mydomain.com --apache acme.sh --issue -d mydomain.com --nginx
使用nginx模式在安裝過程當中遇到錯誤
[Mon Mar 2 15:42:33 UTC 2020] Can not find conf file for domain seyana.life [Mon Mar 2 15:42:33 UTC 2020] Please add '--debug' or '--log' to check more details.
這是由於在nginx中,我配置server_name 爲localhost
server_name localhost
acme.h是根據這個獲取域名的,因此會出錯,須要爲綁定的域名
設置好後從新運行就成功了。
用提供的命令能夠一次把證書和key複製到指定目錄
acme.sh --installcert -d www.xxxxx.come \ --key-file /root/ssl/key/key.pem \ --fullchain-file /root/ssl/cert/cert.pem \ --reloadcmd "service nginx force-reload"
不建議把證書留在~/.acme.sh/中,
關於配置,不提供自動配置,須要本身配置
下面是nginx的443配置例子
server { listen 443 ssl; server_name www.xxx.com xxx.com;#域名 ssl_certificate /root/ssl/cert/cert.pem;#證書路徑 ssl_certificate_key /root/ssl/key/key.pem;#key路徑 #... }
以後能夠用301永久重定向把http 的80端口也轉發到443上
rewrite ^/(.*)$ https://www.****.com/$1 permanent;
這樣即便用http訪問也會跳轉到https上,固然這樣的轉換方式仍然存在風險,能夠開啓HSTS固定訪問https等措施,具體仍是留到https優化裏把。
小鎖鎖get√
acme.sh --upgrade #更新 acme.sh --upgrade --auto-upgrade #開啓自動更新 acme.sh --upgrade --auto-upgrade 0 #關閉自動更新
更多更高級的用法在wiki上 wwwww