Bảo mật cho Apache server là một trong những việc quan trọng nhất của Webmaster. Ở bài viết này, An Ninh Mạng sẽ hướng dẫn cấu hình Apache HTTP Secure Server, dùng chứng chỉ SSL cài cho Apache web server, trên nền tảng hệ điều hành CentOS 7. Cách này cũng có thể được thực hiện trên hệ thống chạy Fedora hoặc Redhat.
Hệ thống chuẩn bị :
Hệ điều hành : CentOS 7.
Địa chỉ IP : 192.168.28.134
Subnet Mask : 255.255.255.0
Hostname : storage-server.anninhmang.local
Tiến hành tạo Certificates :
Đi đến thư mục Certs :
# cd /etc/pki/tls/certs
Chạy dòng lệnh sau để tiến hành tạo File Server key :
Writing RSA key :
# openssl rsa -in server.key -out server.key Enter pass phrase cho server.key: writing RSA key
Generate CSR key file :
Sign key và tạo Expiration days :
# openssl x509 -in server.csr -out server.crt -req -signkey server.key -days 1000 Signature ok subject=/C=NL/ST=Amsterdam/L=Default City/O=anninhmang/OU=anninhmang Hosting/CN=storage-server.anninhmang.local/[email protected]
Getting Private key
Cấu hình SSL Key với Apache :
# yum -y install httpd mod_ssl
Enable và Start dịch vụ Apache :
Cấu hình file ‘/etc/httpd/conf.d/ssl.conf’ :
Mở file ra :
#mv /etc/httpd/conf.d/ssl.conf /etc/httpd/conf.d/ssl.conf.orig #vi /etc/httpd/conf.d/ssl.conf
LoadModule ssl_module modules/mod_ssl.so Listen 443 SSLPassPhraseDialog builtin SSLSessionCache shmcb:/var/cache/mod_ssl/scache(512000) SSLSessionCacheTimeout 300 SSLRandomSeed startup file:/dev/urandom 256 SSLRandomSeed connect builtin SSLCryptoDevice builtin <VirtualHost *:443> DocumentRoot "/var/www/html" ServerName 127.0.0.1:443 ErrorLog logs/ssl_error_log TransferLog logs/ssl_access_log LogLevel warn SSLEngine on SSLProtocol all -SSLv2 SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW SSLCertificateFile /etc/pki/tls/certs/server.crt SSLCertificateKeyFile /etc/pki/tls/certs/server.key <Files ~ "\.(cgi|shtml|phtml|php3?)$"> SSLOptions +StdEnvVars </Files> <Directory "/var/www/cgi-bin"> SSLOptions +StdEnvVars </Directory> SetEnvIf User-Agent ".*MSIE.*" \ nokeepalive ssl-unclean-shutdown \ downgrade-1.0 force-response-1.0 CustomLog logs/ssl_request_log \ "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b" </VirtualHost>
Save và exit.
Restart Apache :
Check lại để xem Port 80 và 443 đã được mở chưa :
Nếu chưa tiến hành mở 2 cổng 80 và 443 trên Iptables :
vi /etc/sysconfig/iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT Reload and restart iptables
Nếu đang sử dụng Firewalld, nhập thêm dòng lệnh :
firewall-cmd --permanent --add-port=80/tcp firewall-cmd --permanent --add-port=443/tcp
và reload lại Firewall :
service iptables restart
hoặc
firewall-cmd --reload
Mở trình duyệt lên và kiểm tra theo đường dẫn : https:// 192.168.28.134
Như vậy là chúng ta đã hoàn thành phần cài đặt SSL cho Apache Server.
- cài ssl cho apache
- cấu hình ssl cho apache
- cấu hình ssl cho web server
- cấu hình https cho website
- hướng dẫn cấu hình https
- cài đặt ssl cho apache