配合cloudflare給nginx/apache安裝證書

下載letsencrypt工具
git clone https://github.com/letsencrypt/letsencrypt

到下載的目錄下
cd letsencrypt/

執行下面命令,給certbot-auto 安裝所需要的環境
./letsencrypt-auto

執行下面命令生成證書,生成的過程中會需要你添加txt記錄到cloudflare,添加上去就行,
./certbot-auto certonly -d xxxxxx.com -d www.xxxxxx.com --manual --preferred-challenges dns-01 --server https://acme-v02.api.letsencrypt.org/directory -v

生成完之後會成/etc/letsencrypt/live/xxxxxx.com有下面一文件
cert.pem chain.pem fullchain.pem privkey.pem README
其中cert.pem是公鑰 privkey.pem是私鑰

nginx配置證書如下
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/xxxxxx.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/xxxxxx.com/privkey.pem;

apache裏面的配置如下
<VirtualHost *:443>
DocumentRoot "xxxxxx/xxx/xxx"
ServerName www.xxxxxx.com
ServerAlias xxxxxx.com
SSLEngine on
SSLProtocol all -sslv2
SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5
SSLCertificateFile "/etc/letsencrypt/live/xxxxxx.com/cert.pem"
SSLCertificateKeyFile "/etc/letsencrypt/live/xxxxxx.com/privkey.pem"
<FilesMatch ".(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory "xxxxxx/xxx/xxx">
AllowOverride All
SSLOptions +StdEnvVars
</Directory>
</VirtualHost>

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