搬瓦工VPS也上SSL证书

搬瓦工中文网拥有多个BandwagonHost VPS。最近新上的KVM VPS也装了LNMP,不过当时忘搞SSL了,最近看的不少网站都支持SSL了,而且免费的SSL以Let’s Encrypt最为红火,这里BandwagonHost中文网也来玩玩在搬瓦工VPS上安装Let’s Encrypt证书的过程。

PS:Let’s Encrypt是国外一个公共的免费SSL项目,由 Linux 基金会托管,Mozilla、思科、Akamai、IdenTrust和EFF等组织发起,目的就是向网站自动签发和管理免费证书,以便加速互联网由HTTP过渡到HTTPS,目前OVH等大公司已经加入赞助行列。

好了,搬瓦工中文网就不多废话了,上过程:

如果是CentOS 6、7,先执行:

yum install epel-release

然后在root下依次执行以下语句:

cd /root/
wget https://dl.eff.org/certbot-auto --no-check-certificate
chmod +x ./certbot-auto
./certbot-auto -n

./certbot-auto -n只是用来安装依赖包的,也可以跳过直接到下面的生成证书的步骤。

单域名生成证书:

./certbot-auto certonly --email [email protected] --agree-tos --no-eff-email --webroot -w /home/wwwroot/www.xxx.net -d www.xxx.net

多域名单目录生成单证书:

./certbot-auto certonly --email [email protected] --agree-tos --no-eff-email --webroot -w /home/wwwroot/www.xxx.net -d www.xxx.net -d test.xxx.net

多域名多目录生成一个证书:

./certbot-auto certonly --email [email protected] --agree-tos --no-eff-email --webroot -w /home/wwwroot/www.aaa.net -d www.aaa.net -d bbs.aaa.net -w /home/wwwroot/www.bbb.net -d www.bbb.net -d bbb.net

如果提示以下内容,安装免费SSL成功。

IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at
/etc/letsencrypt/live/www.xxx.net/fullchain.pem. Your cert will
expire on 2017-9-01. To obtain a new or tweaked version of this
certificate in the future, simply run certbot-auto again. To
non-interactively renew *all* of your certificates, run
"certbot-auto renew"
- If you like Certbot, please consider supporting our work by:

Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le

生成的证书会存在:/etc/letsencrypt/live/www.xxx.net/ 目录下。

很明显,Let’s Encrypt免费SSL证书只能用三个月,到期前执行以下命令,即可续期三个月:

certbot-auto renew

结合crontab即可实现自动续费了。

完成以上后,再就是修改nginx.conf文件了。这里,搬瓦工中文网给个示范:

server
{
listen      80;
server_name www.xxx.cn xxx.cn;
return      301 https://www.xxx.cn$request_uri;
#index index.html index.htm index.php default.html default.htm default.php;
#root  /home/wwwroot/www.xxx.cn;
}

server
{
        #listen 80;
        listen 443 ssl;
#listen [::]:80;
server_name www.xxx.cn xxx.cn;
index index.html index.htm index.php default.html default.htm default.php;
root  /home/wwwroot/www.xxx.cn;
ssl on;
ssl_certificate /etc/letsencrypt/live/www.xxx.cn/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/www.xxx.cn/privkey.pem;
ssl_ciphers "EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5";
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 24h;

include wordpress.conf;
#error_page   404   /404.html;

.........

自己对照修改,就能成功【特别注意红色部分。】,修改后重启LNMP,再访问试试,是不是网站已经支持高大上的SSL安全证书了。

BandwagonHost官网:点击直达

 

8 thoughts to “搬瓦工VPS也上SSL证书”

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注