การเปิดใช้งาน 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
Listen 443 NameVirtualHost *:443
- โหลด mod_ssl ด้วยการแก้ไขไฟล์ /etc/http/conf.d/ssl.conf
LoadModule ssl_module modules/mod_ssl.so
- เพิ่ม config VirtualHost ด้านล่างเข้าไปที่ด้านล่างของไฟล์ /etc/http/conf.d/ssl.conf และแก้ไขที่อยู่ของไฟล์ certificate, ServerName และ path ของ 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
Listen 443 NameVirtualHost *:443
- เพิ่มค่าด้านล่างเพื่อโหลด gnutls_module ในไฟล์ /etc/http/conf.d/ssl.conf
LoadModule gnutls_module modules/mod_gnutls.so
- เพิ่ม config VirtualHost ด้านล่างเข้าไปที่ด้านล่างของไฟล์ /etc/http/conf.d/ssl.conf และแก้ไขที่อยู่ของไฟล์ certificate, ServerName และ path ของ 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
Related posts:
- How to configure Active Directory authentication with Apache web server การ authen ผ่าน Active directory หรือ LDAP เป็นทางเลือกที่สะดวกสบายและง่ายต่อการบริหารจัดการกับผู้ใช้งานภายในองค์กรณ์...
- Setup a transparent proxy over ssl https with Squid การนำ Squid มาทำ transparent proxy ส่วนใหญ่จะใน website ต่างๆจะบอกแต่วิธีทำ...
- Transparent proxy in squid 2.6 การ config transparent proxy ตั้งแต่ squid version 2.6...
- How to enable xdmcp เมื่อต้องการที่จะเปิดการทำงานของ xdmcp ในปัจจุบันไฟล์ config ของ xdmcp ได้ถูกเปลี่ยนแปลงไป จากเดิมอยู่ที่...
- Proxy Auto Configuration (PAC) – Proxy auto-config เรื่องนี้อาจจะเก่าสำหรับหลายๆคน แต่สำหรับผมแล้วเป็นเรื่องใหม่ เพราะเมื่อสองสามวันมานี้เกิดคำถามกับตัวเองว่า ถ้าเราต้องการใช้งาน proxy เฉพาะบางเวป และเวปที่อื่นๆให้ออกตรงโดยไม่ต้องผ่าน proxy...


December 11th, 2011
Tum.
Posted in
Tags: 
Historically, if you wanted to host multiple SSL enabled Web sites, you had to have an unique IP address for each site….