centos 7 nginx 1.10.2
yum install -y epel-release yum install -y certbot
方法1:在網站根目錄下建立一個.well-known的目錄 方法2: mkdir -p /usr/local/nginx/cert/.well-known ln -s /usr/local/nginx/cert/.well-known /data/www/example.com/.well-known ln -s /usr/local/nginx/cert/.well-known /data/www/test.example.com/.well-known
certbot certonly --webroot -w /usr/local/nginx/cert -d example.com -d test.example.com 根據提示進行操做,通常能夠正常生產證書文件。 證書文件的目錄存放在: '/etc/letsencrypt/live/example.com/' 會有4個文件: cert.pem chain.pem fullchain.pem privkey.pem 特別要注意,這條命令只會將生成的證書放在這個目錄,不會有一個/etc/letsencrypt/live/test.example.com/目錄,test.example.com的證書和example.com的證書放在一塊兒了,具體看後面的nginx配置。
server { listen 443 ssl http2; server_name example.com; index index.html index.htm index.php; root /data/www/example.com; ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH"; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; ssl_session_cache shared:SSL:10m; access_log off; } server { listen 443 ssl http2; server_name test.example.com; index index.html index.htm index.php; root /data/www/test.example.com; ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH"; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; ssl_session_cache shared:SSL:10m; access_log off; }
crontab -e # 新增以下定時任務 10 6 * * * /bin/certbot renew --quiet &>/dev/null Let's Encrypt 的證書有效期爲90天,若是證書的有效期大於30天,則上面命令不會真的去更新證書的。
在瀏覽器輸入 https://example.com 網址進行驗證,通常Chrome會有一個綠色的鎖以及Secure標示。php
最後若是以爲所講的東西可以幫助到你,而且但願瞭解更多的知識,進行更詳細的深刻的學習,歡迎加羣632109190進行討論和學習。html