Chủ Nhật, 5 tháng 6, 2011

Thiết lập mod_ssl trên Centos 5

SSL - Secure Sockers Layer
Khi website của bạn chạy trong môi trường SSL thì toàn bộ dữ liệu trao đổi giữa client và server của bạn sẽ được mã hóa. Còn cách thức cụ thể thế nào thì bạn đọc:

HTML Code:
http://en.wikipedia.org/wiki/Secure_Sockets_Layer

B1: Cài đặt

Login root thực hiện lệnh

HTML Code:
yum install mod_ssl openssl

B2: Tạo ra một chứng chỉ ký tự

HTML Code:
openssl genrsa -out ca.key 1024 # Generate private key # Generate CSR openssl req -new -key ca.key -out ca.csr # Generate Self Signed Key openssl x509 -req -days 365 -in ca.csr -signkey ca.key -out ca.crt # Move the files to the correct locations mv ca.crt /etc/pki/tls/certs mv ca.key /etc/pki/tls/private/ca.key mv ca.csr /etc/pki/tls/private/ca.csr

Sau đó, chúng ta cần phải cập nhật các file cấu hình Apache SSL

HTML Code:
vi +/SSLCertificateFile /etc/httpd/conf.d/ssl.conf

Thay đổi đường dẫn cho phù hợp mà tập tin chính được lưu trữ

HTML Code:
SSLCertificateFile /etc/pki/tls/certs/ca.crt

Sau đó thiết lập đường dẫn chính xác cho các khóa

HTML Code:
SSLCertificateKeyFile /etc/pki/tls/private/ca.key

Thoát và lưu các tập tin và sau đó khởi động lại Apache

HTML Code:
/etc/init.d/httpd restart

Tiếp theo: Thiết lập các máy chủ ảo

HTML Code:
<VirtualHost *:80> <Directory /var/www/vhosts/yoursite.com/httpdocs> AllowOverride All </Directory> DocumentRoot /var/www/vhosts/yoursite.com/httpdocs ServerName yoursite.com </VirtualHost>

Để chạy trên cổng 443 chúng ta cần thay đổi như sau:

HTML Code:
NameVirtualHost *:443

Kêt quả như sau:

HTML Code:
<VirtualHost *:443> SSLEngine on SSLCertificateFile /etc/pki/tls/certs/ca.crt SSLCertificateKeyFile /etc/pki/tls/private/ca.key <Directory /var/www/vhosts/yoursite.com/httpsdocs> AllowOverride All </Directory> DocumentRoot /var/www/vhosts/yoursite.com/httpsdocs ServerName yoursite.com </VirtualHost>

Restart Apache lần nữa:

HTML Code:
/etc/init.d/httpd restart

Bây giờ bạn sẽ có một trang web làm việc trên https. Nếu bạn không thể kết nối bạn có thể cần phải mở các cổng trên tường lửa của bạn:

HTML Code:
iptables -A INPUT -p tcp --dport 443 -j ACCEPT /sbin/service iptables save iptables -L -v

0 nhận xét:

Đăng nhận xét

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by netdohoa | Support for this Theme dohoavietnam