Code:
groupadd apache
Code:
useradd apache
Việc tiếp theo cần làm đó là cấu hình apache.
./configure \
--prefix=/usr/local/apache2 \
--with-mpm=prefork \
--enable-ssl \
--disable-charset-lite \
--disable-include \
--disable-env \
--disable-status \
--disable-autoindex \
--disable-asis \
--disable-cgi \
--disable-negotiation \
--disable-imap \
--disable-actions \
--disable-userdir \
--disable-alias \
--disable-so
Sau khi đã cấu hình và cài đặt Apache thành công ta có thể tiếp tục tuỳ chỉnh 1 vài thay đổi trên Apache nhằm tối ưu vấn đề tốc độ và tính an toàn
- tạo 1 trang web mẫu để phục vụ cho việc Test
Code:
umask 022 mkdir /www echo " \ Test works." > /www/index.html chown -R root:sys /www
- tuỳ chỉnh file cấu hình Apache (trong trường hợp này là /usr/local/apache2/conf/httpd.conf )
Code:
# =================================================
# Basic settings
# =================================================
User apache
Group apache
ServerAdmin <a href="mailto:webmaster@www.seccure.lab">webmaster@www.seccure.lab</a>
ServerName www.seccure.lab
UseCanonicalName Off
ServerSignature Off
HostnameLookups Off
ServerTokens Prod
ServerRoot "/usr/local/apache2"
DocumentRoot "/www"
PidFile /usr/local/apache2/logs/httpd.pid
ScoreBoardFile /usr/local/apache2/logs/httpd.scoreboard
DirectoryIndex index.html
# =================================================
# HTTP and performance settings
# =================================================
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 30
MinSpareServers 5
MaxSpareServers 10
StartServers 5
MaxClients 150
MaxRequestsPerChild 0
# =================================================
# Access control
# =================================================
Options None
AllowOverride None
Order deny,allow
Deny from all
Order allow,deny
Allow from all
# =================================================
# MIME encoding
# =================================================
TypesConfig /usr/local/apache2/conf/mime.types
DefaultType text/plain
AddEncoding x-compress .Z
AddEncoding x-gzip .gz .tgz
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-tar .tgz
AddType application/x-x509-ca-cert .crt
AddType application/x-pkcs7-crl .crl
# =================================================
# Logs
# =================================================
LogLevel warn
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
ErrorLog /usr/local/apache2/logs/error_log
CustomLog /usr/local/apache2/logs/access_log combined
CustomLog logs/ssl_request_log \
"%t %h %{HTTPS}x %{SSL_PROTOCOL}x %{SSL_CIPHER}x \
%{SSL_CIPHER_USEKEYSIZE}x %{SSL_CLIENT_VERIFY}x \"%r\" %b"
# =================================================
# SSL/TLS settings
# =================================================
Listen 0.0.0.0:443
SSLEngine on
SSLOptions +StrictRequire
SSLRequireSSL
SSLProtocol -all +TLSv1 +SSLv3
SSLCipherSuite HIGH:MEDIUM:!aNULL:+SHA1:+MD5:+HIGH:+MEDIUM
SSLMutex file:/usr/local/apache2/logs/ssl_mutex
SSLRandomSeed startup file:/dev/urandom 1024
SSLRandomSeed connect file:/dev/urandom 1024
SSLSessionCache shm:/usr/local/apache2/logs/ssl_cache_shm
SSLSessionCacheTimeout 600
SSLPassPhraseDialog builtin
SSLCertificateFile /usr/local/apache2/conf/ssl.crt/server.crt
SSLCertificateKeyFile /usr/local/apache2/conf/ssl.key/server.key
SSLVerifyClient none
SSLProxyEngine off
AddType application/x-x509-ca-cert .crt
AddType application/x-pkcs7-crl .crl
SetEnvIf User-Agent ".*MSIE.*" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
- khởi tạo thư mục chứa private key
mkdir /usr/local/apache2/conf/ssl.key
mkdir /usr/local/apache2/conf/ssl.crt
mkdir /usr/local/apache2/conf/ssl.crl
OK
Tiếp theo chúng ta tiếp tục tào 1 self-signed certificate ( certificate chỉ danh cho việc Test, các certificate thực các bạn phải mua ). Phương thức này được đưa ra chỉ để tiếp tục quá trình kiểm tra của chúng ta, hoặc dùng trong môi trường nhỏ. Để web browser có thể nhận dạng được web server chứng chỉ tự kí phải được cài đặt vào mọi web browser cần truy cập web server đó
openssl req \
-new \
-x509 \
-days 30 \
-keyout /usr/local/apache2/conf/ssl.key/server.key \
-out /usr/local/apache2/conf/ssl.crt/server.crt \
-subj '/CN=Test-Only Certificate'
Với việc cấu hình như trên chúng ta đã tạo ra 1 Certicate X509 có thời hạn là 30 ngày. Cặp khoá public/private sẽ được sinh ra trong sever.key và server.crt. Mặc đinh thuật toán mã hoá sẽ được sử dụng là RSA 1024 bit. Chúng ta có thể tuỳ chỉnh tham số này bằng việc thêm
Code:
-newkey rsa:1024
vào file cấu hình
Giờ chúng ta đã có thể Start dịch vụ rồi
Code:
/usr/local/apache2/bin/apachectl startssl
và kết quả trả về
Code:
Apache/2.0.52 mod_ssl/2.0.52 (Pass Phrase Dialog) Some of your private key files are encrypted for security reasons. In order to read them you have to provide us with the pass phrases. Server 127.0.0.1:443 (RSA) Enter pass phrase:************* Ok: Pass Phrase Dialog successful. [/code/ Trong quá trình cài đặt và chạy thử nghiệm nếu gặp lỗi chúng ta có thể sử dụng
chức năng [b]s_client[/b] có sẵn trong mod_ssl. Đây là 1 chức năng khá hay và
có nhiều tuỳ chọn hữu ích. Chẳng hạn như tắt/mở (on/off) một giao thức cụ thể
(-ssl2 , -ssl3, -tls1). [code] /usr/bin/openssl s_client -connect localhost:443
Sau đó khởi động lại Apache và kiểm tra các file đăng nhập (/usr/local/apache2/logs/) để có thêm thông tin và từ đó xác đinh nguyên nhân
Cheer
No comments:
Post a Comment