在Debian系统上配置Nginx以支持SNI(Server Name Indication)是一个相对简单的过程。SNI允许你在同一个IP地址和端口上托管多个SSL证书,每个证书对应不同的域名。以下是详细步骤:
如果你还没有安装Nginx,可以使用以下命令进行安装:
sudo apt update
sudo apt install nginx
你可以从Let’s Encrypt或其他证书颁发机构获取SSL证书。假设你已经有了证书文件,通常包括:
certificate.crt(你的域名证书)private.key(你的域名私钥)chain.pem(中间证书链,如果有的话)编辑Nginx的配置文件,通常位于 /etc/nginx/sites-available/ 目录下。你可以创建一个新的配置文件或编辑现有的配置文件。
假设你的域名是 example.com,你可以创建一个名为 example.com.conf 的文件:
sudo nano /etc/nginx/sites-available/example.com.conf
在文件中添加以下内容:
server {
listen 443 ssl http2;
server_name example.com www.example.com;
ssl_certificate /path/to/certificate.crt;
ssl_certificate_key /path/to/private.key;
ssl_trusted_certificate /path/to/chain.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
root /var/www/example.com;
index index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
# 其他配置...
}
创建一个符号链接将配置文件链接到 sites-enabled 目录:
sudo ln -s /etc/nginx/sites-available/example.com.conf /etc/nginx/sites-enabled/
检查Nginx配置是否正确:
sudo nginx -t
如果没有错误,重启Nginx以应用更改:
sudo systemctl restart nginx
你可以使用浏览器访问你的网站,或者使用命令行工具如 curl 来验证SNI是否正常工作:
curl -v https://example.com
在输出中,你应该能看到 Server Name Indication 的相关信息。
server 块,并在 server_name 中指定相应的域名。通过以上步骤,你应该能够在Debian系统上成功配置Nginx以支持SNI。