摘要:为Ubuntu配置域名的SSL证书,需要使用 Certbot 工具和 Nginx 服务器。以下是大致步骤:
1. 安装Certbot
首先,需要安装certbot工具,以便生成SSL证书。可以通过运行以下命令来安装certbot:
sudo apt-get update
2. 配置nginx
在Nginx服务器上配置你的二级域名。进入配置文件
sudo /etc/nginx
sudo vi nginx.conf
在配置文件的 http{} 内添加如下配置
server {
listen 80;
server_name example.com;
location / {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl;
server_name example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
location / {
root /opt/example-name;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
}
3. 获取SSL证书
sudo certbot --nginx -d example.com -d www.example.com
请将 “example.com” 替换为您的实际域名
4. 确认证书安装
在成功获取SSL证书后,Certbot 工具会将证书自动安装到 Nginx服务器中。你可以通过访问你的https://example.com 来测试证书是否已正确锁定。