这里以nginx+ubuntu 18.04为例。
本文采用的是 certbot 的方法。
配置nginx
首先在Ubuntu 18.04上安装nginx。安装完成以后,打开/etc/nginx/nginx.conf
。在http
中添加server
,具体如下所示。
server {
listen 80; //监听80端口
server_name your_domain; #此处填写域名
location / { # 根路径
root your_webpage_path; #网页在系统的路径,例如:/home/username/my_webapp
index index.html; # 指定主页
}
}
完了以后,使用nginx -t
检查一下配置文件是否有错误。如果没有错误。网页就可以通过http访问了。
使用certbot配置Let’s Encrypt证书
访问certbot,选择web服务器类型和系统发行版。这里以nginx+ubuntu 18.04 LTS为例。
运行一下命令安装certbot
sudo apt-get update
sudo apt-get install software-properties-common
sudo add-apt-repository universe
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install python-certbot-nginx
运行完以后,会让你输入你的Email地址,接受紧急邮件。同时会问你是否愿意share你的Email地址,当然,我个人是选不愿意。
弄好以后,运行以下命令:
sudo certbot --nginx
会自动读取nginx的配置,列出nginx配置过的域名。然后按照提示选择需要申请证书的域名即可。
走完流程了,也会自动修改nginx配置。一切按照提示来就行了。这里我是将http重定向到https,具体按照提示来。
配置完以后,启动nginx即可访问网站了。