使用Let's Encrypt讓域名支持HTTPS

安裝 acme.sh

curl  https://get.acme.sh | sh

安裝成功後執行 source ~/.bashrc 以確保腳本所設置的命令別名生效nginx

若是安裝報錯,那麼多是由於系統缺乏 acme.sh 所須要的依賴項,acme.sh 的依賴項主要是 netcat(nc),咱們經過如下命令來安裝這些依賴項,而後從新安裝一遍 acme.sh:bash

sudo apt-get -y install netcat

安裝socat

sudo apt-get -y install socat

使用 acme.sh 生成證書

sudo ~/.acme.sh/acme.sh --issue -d wechatrobot.doodl6.com --standalone -k ec-256 --force

手動更新 ECC 證書session

sudo ~/.acme.sh/acme.sh --renew -d wechatrobot.doodl6.com --force --ecc

安裝證書和密鑰

sudo ~/.acme.sh/acme.sh --installcert -d wechatrobot.doodl6.com --fullchainpath /etc/encrypt/wechatrobot.doodl6.com.crt --keypath /etc/encrypt/wechatrobot.doodl6.com.key --ecc --force

配置nginx

server{
        listen               443 ssl;
        server_name          wechatrobot.doodl6.com

        charset UTF-8;

        ssl                  on; 
        ssl_certificate     /etc/encrypt/wechatrobot.doodl6.com.crt;
        ssl_certificate_key /etc/encrypt/wechatrobot.doodl6.com.key;
        ssl_session_timeout 5m;

        location / {
                proxy_pass http://127.0.0.1:8080;
                proxy_set_header Host wechatrobot.doodl6.com;
        }
}
server {
    listen 80;
    server_name wechatrobot.doodl6.com;

    rewrite ^(.*)$  https://$host$1 permanent;
}
相關文章
相關標籤/搜索