Enable multiple SSL vhosts on a single IP with Apache
ภาพประกอบเดิม: Apache with ssl certificate = https — ไม่พบไฟล์ภาพในชุดข้อมูลเดิม
การเปิดใช้งาน https ที่รองรับ SSL certificate หลายใบบน port 443 ของ Apache เมื่อหลายปีก่อนดูเหมือนจะเป็นเรื่องยุ่งยาก แต่การมาของ SNI หรือ Server Name Indication ทำให้ชีวิตง่ายขึ้นเยอะมาก เพราะ SNI สามารถอนุญาตให้เรา config virtual host ให้สามารถมี SSL certificate ไม่ซ้ำกันได้บน 1 IP address + port 443 แต่การใช้งาน SNI ยังมีข้อจำกัดอยู่ คือ รองรับ web browser ได้ไม่ทั้งหมดทุก version แต่สำหรับ web browser version ใหม่ๆรองรับทั้งหมดแล้ว สามารถตรวจสอบ version ที่สามารถใช้งานได้จากด้านล่าง
- Opera 8.0+ (with TLS 1.1 enabled)
- Firefox 2+
- Internet Explorer 7+
- Safari 3.2.1+ on Vista or higher and Mac OS X 10.5.6 or higher
- Chrome (NOT Chromium) on Vista or higher
สำหรับ module ที่ใช้ในการ config เพื่อเปิดใช้งาน https ที่รองรับ SSL certificate หลายใบบน port 443 หรือ SNI ของ Apache มีอยู่ด้วยกัน 2 module คือ SSL module (mod_ssl) และ mod_gnutls ข้อแตกต่างระหว่าง module ทั้งสองคือ mod_ssl จะต้องใช้กับ Apache 2.2.8 ขึ้นไป แต่ mod_gnutls เป็น module เพิ่มเติมและไม่ require Apache version 2.2.8 การ config SSL virtual hosts จะมีความคล้ายกับการ config virtual hosts ทั่วไป เพียงแต่แก้ไข port จาก 80 เป็น 443 และเปิดใช้ SSL certificate เท่านั้น สำหรับตัวอย่างการ config ในบทความนี้จะยกตัวอย่างการ config ให้ดูทั้ง 2 แบบ คือ mod_ssl และ mod_gnutls โดยสามารถทำตามขั้นตอนได้ดังนี้ Enable multiple SSL vhosts ด้วย mod_ssl
-
config ให้ apache เปิด port 443, กำหนดค่า NameVirtualHost และโหลด mod_ssl ที่ไฟล์ /etc/http/conf.d/ssl.conf
Listen 443 NameVirtualHost *:443 ... LoadModule ssl_module modules/mod_ssl.so -
เพิ่ม config VirtualHost ด้านล่างเข้าไปที่ด้านล่างของไฟล์ /etc/http/conf.d/ssl.conf หรือ ที่อื่นๆที่ได้กำหนดไว้ และให้แก้ไขที่อยู่ของไฟล์ certificate, ServerName และค่า config ต่างๆของ website
<VirtualHost *:443> SSLEngine on SSLCertificateFile /etc/apache2/ssl/server1.crt SSLCertificateKeyFile /etc/apache2/ssl/server1.key ServerName secure.ezylinux.com DocumentRoot /path/to/www/site1 <Directory /path/to/www/site1> SSLRequireSSL Order Deny,Allow Allow from All </Directory> </VirtualHost> <VirtualHost *:443> SSLEngine on SSLCertificateFile /etc/htt/ssl/server2.crt SSLCertificateKeyFile /etc/http/ssl/server2.key ServerName secure.ezylinux.com DocumentRoot /path/to/www/site2 <Directory /path/to/www/site2> SSLRequireSSL Order Deny,Allow Allow from All </Directory> </VirtualHost>
Enable multiple SSL vhosts ด้วย mod_gnutls
-
Install gnutls_module ด้วยคำสั่ง (สำหรับ CentOS 5)
[root@Ezylinux ~]# yum install mod_gnutls --enablerepo=c5-testing -
config ให้ apache เปิด port 443, กำหนดค่า NameVirtualHost และเพิ่มค่าด้านล่างเพื่อโหลด gnutls_module ในไฟล์ /etc/http/conf.d/ssl.conf
Listen 443 NameVirtualHost *:443 ... LoadModule gnutls_module modules/mod_gnutls.so -
เพิ่ม config VirtualHost ด้านล่างเข้าไปที่ด้านล่างของไฟล์ /etc/http/conf.d/ssl.conf และแก้ไขที่อยู่ของไฟล์ certificate, ServerName และค่า config ต่างๆ ของ website
<VirtualHost *:443> GnuTLSEnable on GnuTLSExportCertificates on GnuTLSCacheTimeout 500 GnuTLSCertificateFile /etc/http/ssl/server1.crt GnuTLSClientCAFile /etc/http/ssl/CA-bundle1.crt GnuTLSKeyFile /etc/http/ssl/server1.key ServerName secure1.ezylinux.com DocumentRoot /path/to/www/site1 <Directory /path/to/www/site1> Order Deny,Allow Allow from All </Directory> </VirtualHost> <VirtualHost *:443> GnuTLSEnable on GnuTLSExportCertificates on GnuTLSCacheTimeout 500 GnuTLSCertificateFile /etc/http/ssl/server2.crt GnuTLSClientCAFile /etc/http/ssl/CA-bundle2.crt GnuTLSKeyFile /etc/http/ssl/server2.key ServerName secure2.ezylinux.com DocumentRoot /path/to/www/site2 <Directory /path/to/www/site2> Order Deny,Allow Allow from All </Directory> </VirtualHost>
หลังจาก config เสร็จเรียบร้อยแล้วสามารถตรวจสอบการใช้งานได้โดยใช้ web browser โดยเข้าไปที่ https://secure1.ezylinux.com และ https://secure/.ezylinux.com หรือสามารถใช้คำสั่ง OpenSSL’s s_client ก็ได้โดยรันคำสั่ง
[root@Ezylinux ~]# openssl s_client -connect secure1.ezylinux.com:443
[root@Ezylinux ~]# openssl s_client -connect secure2.ezylinux.com:443
ความคิดเห็นเดิม (1)
เก็บจากบล็อกเดิมเพื่ออ่านอ้างอิง
Historically, if you wanted to [host multiple SSL enabled Web sites](/en/enable-multiple-ssl-vhosts-and-certificates-on-a-single-ip-with-apache/), you had to have an unique IP address for each site....