Cách thiết lập nhiều chứng chỉ SSL trên một IP với Lighttpd
Chỉ báo tên server (SNI) là một tính năng của giao thức TLS cho phép cài đặt nhiều certificate SSL trên một địa chỉ IP.Lighttpd phải được cài đặt và đang chạy. Đọc những bài báo này để có được nó.
Cài đặt
Hai domain sẽ được sử dụng cho hướng dẫn này. Cả hai đều sẽ sử dụng certificate SSL tự ký.
 Miền 1: example.com
 Tên thường gọi: * .example.com
 Miền 2: digitalocean.com
 Tên thường gọi: www.digitalocean.com
Cài đặt SSL cần một certificate mặc định giống như một server ảo mặc định. Ta sẽ sử dụng certificate của domain đầu tiên cho việc này.
Tạo private key
 Tạo một folder  bên trong /etc/lighttpd để đặt các khóa và certificate .
mkdir /etc/lighttpd/certs Tạo private key và nhập passphrase (password bảo vệ) . Lệnh thứ hai là để loại bỏ passphrase (password bảo vệ) .
cd /etc/lighttpd/certs openssl genrsa -des3 -out example.com.key 2048 openssl rsa -in example.com.key -out example.com.key Làm tương tự cho domain thứ hai.
openssl genrsa -des3 -out digitalocean.com.key 2048 openssl rsa -in digitalocean.com.key -out digitalocean.com.key Nếu passphrase (password bảo vệ) không bị xóa, Lighttpd sẽ nhắc passphrase (password bảo vệ) đó mỗi khi khởi động hoặc khởi động lại.
Tạo yêu cầu ký certificate
Tạo CSR cho cả hai domain .
cd /etc/lighttpd/certs openssl req -new -key digitalocean.com.key -out digitalocean.com.csr openssl req -new -key example.com.key -out example.com.csr Điền thông tin chi tiết và nhập dấu chấm . nếu bạn muốn để trống một trường.
----- Country Name (2 letter code) [AU]:US State or Province Name (full name) [Some-State]:. Locality Name (eg, city) []:NYC Organization Name (eg, company) [Internet Widgits Pty Ltd]:DigitalOcean Inc Organizational Unit Name (eg, section) []:. Common Name (e.g. server FQDN or YOUR name) []:www.digitalocean.com Email Address []:webmaster@digitalocean.com  Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []: Khi điền vào trường Tên chung cho example.com hãy đảm bảo nhập *.example.com .
----- Country Name (2 letter code) [AU]:IN State or Province Name (full name) [Some-State]:. Locality Name (eg, city) []:Chennai Organization Name (eg, company) [Internet Widgits Pty Ltd]:. Organizational Unit Name (eg, section) []:. Common Name (e.g. server FQDN or YOUR name) []:*.example.com Email Address []:admin@example.com  Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []: Ta đã nhập một quốc gia và city khác cho CSR này để có thể dễ dàng phân biệt certificate nào được xuất trình.
Ký certificate SSL của bạn
 Ở đây   ,  ta  sẽ đặt độ dài hiệu lực khác nhau (đối số- -days ) cho cả hai certificate  để  ta  có thể dễ dàng phân biệt giữa chúng.
cd /etc/lighttpd/certs openssl x509 -req -days 100 -in example.com.csr -signkey example.com.key -out example.com.crt openssl x509 -req -days 200 -in digitalocean.com.csr -signkey digitalocean.com.key -out digitalocean.com.crt Tạo file  .pem từ certificate  và private key  của chúng.
cat example.com.{key,crt}> example.com.pem cat digitalocean.com.{key,crt}> digitalocean.com.pem Bảo mật các file trong folder này bằng cách chỉ cho phép user root đọc các file này.
chmod -R 400 /etc/lighttpd/certs/ Daemon Lighttpd bắt đầu với quyền root trước khi chuyển xuống www-data nên đây không phải là vấn đề.
Cấu hình Lighttpd cho SSL
 Chỉnh sửa file  /etc/lighttpd/lighttpd.conf và thêm các dòng sau vào cuối.
$SERVER["socket"] == "0.0.0.0:443" {     ssl.engine = "enable"     ssl.pemfile = "/etc/lighttpd/certs/example.com.pem"     $HTTP["host"] =~ "(^|www\.)digitalocean.com" {         ssl.pemfile = "/etc/lighttpd/certs/digitalocean.com.pem"     } } Vì ceritifcate của example.com là mặc định,  ta  không đặt nó bên trong một điều kiện  server .
Khởi động lại daemon Lighttpd.
service lighttpd force-reload Dịch vụ sẽ khởi động lại thành công nếu bạn không mắc lỗi trong đường dẫn certificate  hoặc khi tạo file  .pem .
Thử nghiệm HTTPS
 Cách dễ dàng để kiểm tra điều này mà không cần chỉnh sửa file   server  là sử dụng curl .
 Lệnh này có đối số --resolve ánh xạ các domain  có địa chỉ IP. Thay thế 1.1.1.1 bằng địa chỉ IP của Server.
curl -k -o /dev/null --resolve "www.digitalocean.com:443:1.1.1.1" -s -v https://www.digitalocean.com Điều này sẽ cung cấp một  kết quả  dài dòng. -o chuyển hướng tất cả  kết quả  HTML khi  ta  không cần nó. Đây là đoạn mã mà  ta  quan tâm.
* SSL connection using AES256-SHA * Server certificate: *        subject: C=US; L=NYC; O=DigitalOcean Inc; CN=www.digitalocean.com; emailAddress=webmaster@digitalocean.com *        start date: 2014-03-26 18:39:25 GMT *        expire date: 2014-10-12 18:39:25 GMT *        common name: www.digitalocean.com (matched) *        issuer: C=US; L=NYC; O=DigitalOcean Inc; CN=www.digitalocean.com;    emailAddress=webmaster@digitalocean.com *        SSL certificate verify result: self signed certificate (18), continuing anyway. Kiểm tra domain tiếp theo.
curl -k -o /dev/null --resolve "www.example.com:443:1.1.1.1" -s -v https://www.example.com Thông báo chi tiết từ kết quả :
* SSL connection using AES256-SHA * Server certificate: *        subject: C=IN; L=Chennai; CN=*.example.com; emailAddress=admin@example.com *        start date: 2014-03-26 18:39:20 GMT *        expire date: 2014-07-04 18:39:20 GMT *        common name: *.example.com (matched) *        issuer: C=IN; L=Chennai; CN=*.example.com; emailAddress=admin@example.com *        SSL certificate verify result: self signed certificate (18), continuing anyway. Lưu ý sự khác biệt giữa cả hai certificate trong trường chủ đề: và ngày hết hạn:.
Hãy thử truy cập trực tiếp vào địa chỉ IP.
user@server~$ curl -k -o /dev/null -s -v https://1.1.1.1  * SSL connection using AES256-SHA * Server certificate: *        subject: C=IN; L=Chennai; CN=*.example.com; emailAddress=admin@example.com *        start date: 2014-03-26 18:39:20 GMT *        expire date: 2014-07-04 18:39:20 GMT *        common name: *.example.com (does not match '128.199.206.19') *        issuer: C=IN; L=Chennai; CN=*.example.com; emailAddress=admin@example.com *        SSL certificate verify result: self signed certificate (18), continuing anyway. Kết quả sẽ trả về certificate của example.com .
<div class = “author”> Người gửi: <a rel=p>author[ href=osystemhttp://jesin.tk/[> Jesin A </a> </div>
Các tin liên quan

