很早就申请了很多域名,但是访问起来浏览器老是显示一个不安全,看着真的是不爽,因为自己的网站也没什么内容就没配置https,主要还是看了网上的教程退缩了,觉得比较麻烦。很多证书还要钱,自己也就学习性质地做个网站,所以就没搞,
今天心血来潮就配置了一下,发现真的挺简单的,而且免费,自己学习玩玩够了,在这里记录一下。
nginx的安装在这里就不多说了,可以使用
yum install nginx
也可以编译安装,在这里就不多说了,要注意的一点是要安装ssl模块
官网的教程是snap安装的,我就是这样安装的。
sudo yum install epel-release
sudo yum install snapd
sudo systemctl enable --now snapd.socket
sudo ln -s /var/lib/snapd/snap /snap
这几步下来一般是不会出错的,这样sanp就安装好了
sudo snap install core sudo snap refresh core
如果之前装过certbot的话要先卸载
sudo yum remove certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot
sudo certbot --nginx
或者
sudo certbot certonly --nginx
这里会提示输入邮箱和域名,还要同意协议,成功后会有你证书的储存地址
sudo certbot renew --dry-run
最后这步是检验
进入vim nginx/conf/nginx.conf,找到443端口的部分,记得放开443端口
server { listen 443 ssl; server_name akazwz.com; ssl_certificate /etc/letsencrypt/live/akazwz.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/akazwz.com/privkey.pem; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; location / { root html; index index.html index.htm; } }
这是我的配置,贴在这里大家参考一下
systemctl stop nginx systemctl start nginx systemctl status nginx
这时访问你的网站,就会是https了。
免费的吗,certbot是需要定期续的,所以我们设置个定时任务
echo "0 0 1,8,20 * * root python -c 'import random; import time; time.sleep(random.random() * 3600)' && certbot renew" | sudo tee -a /etc/crontab > /dev/null
这样的话就完成了,但是中间会出现错误,一个是提示找不到nginx,设置个软连接就可以解决
ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx ln -s /usr/local/nginx/conf/ /etc/nginx
还有个错误提示没有安装ssl模块,这个在安装nginx的时候要注意,编译安装的话可以进入安装包输入以下命令:
./configure --with-http_ssl_module make && make install
这样的话就安装上了ssl模块。
这里就记录到这。