在Ubuntu上配置SSL(Secure Sockets Layer)通常涉及以下几个步骤:
安装SSL证书:
sudo apt update
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
配置Nginx:
sudo apt install nginx
/etc/nginx/sites-available/yourdomain.com
,确保包含以下内容:server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
location /.well-known/acme-challenge/ {
root /var/www/certbot;
}
location / {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl;
server_name yourdomain.com www.yourdomain.com;
ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
# 其他配置...
}
sudo nginx -t
sudo systemctl reload nginx
配置防火墙:
sudo ufw allow 'Nginx Full'
测试SSL配置:
https://
开头。自动续期:
sudo certbot renew --dry-run
请注意,这些步骤假设你使用的是Nginx作为Web服务器。如果你使用的是Apache或其他Web服务器,配置过程会有所不同。此外,确保你的域名解析正确指向了你的服务器IP地址。