在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。