配置Debian Nginx SSL以支持SNI(Server Name Indication)主要涉及以下几个步骤:
如果你还没有安装Nginx,可以使用以下命令进行安装:
sudo apt update
sudo apt install nginx
你可以从Let’s Encrypt或其他证书颁发机构获取SSL证书。以下是使用Certbot获取Let’s Encrypt证书的示例:
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
按照提示完成证书的获取和配置。
Certbot生成的Nginx配置文件通常位于/etc/letsencrypt/options-ssl-nginx.conf
。你需要确保Nginx的主配置文件中包含了这些选项。
打开Nginx的主配置文件:
sudo nano /etc/nginx/nginx.conf
在http
块中添加以下内容:
http {
# 其他配置...
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
server {
listen 443 ssl http2;
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;
# 其他配置...
}
# 可以添加更多的server块来支持多个域名
server {
listen 443 ssl http2;
server_name anotherdomain.com www.anotherdomain.com;
ssl_certificate /etc/letsencrypt/live/anotherdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/anotherdomain.com/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
# 其他配置...
}
}
保存并关闭配置文件后,重启Nginx以应用更改:
sudo systemctl restart nginx
你可以使用浏览器访问你的域名,或者使用curl
命令来验证SSL配置是否正确:
curl -I https://yourdomain.com
如果一切配置正确,你应该会看到HTTP响应头中包含Strict-Transport-Security
等SSL相关的头信息。
通过以上步骤,你就可以成功配置Debian Nginx SSL以支持SNI了。