在Ubuntu上启用Nginx SSL,你需要遵循以下步骤:
sudo apt update
sudo apt install nginx
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
将yourdomain.com和www.yourdomain.com替换为你的域名。Certbot将自动配置Nginx以使用SSL证书。
Certbot可能会提示你输入电子邮件地址、同意服务条款等。完成这些步骤后,Certbot将自动更新Nginx配置文件(通常位于/etc/nginx/sites-available/yourdomain.com-le-ssl.conf)以启用HTTPS。
检查Nginx配置文件是否正确:
sudo nginx -t
如果配置正确,你将看到以下输出:
nginx: configuration file /etc/nginx/nginx.conf test is successful
sudo systemctl reload nginx
sudo ufw allow 'Nginx Full'
现在,你的网站应该已经通过HTTPS提供服务。访问https://yourdomain.com(将yourdomain.com替换为你的域名),你应该看到一个绿色的锁图标,表示连接已加密。