1. 需求描述 2. 使用apache 2.4.6實現 2.1. 編譯安裝apache 2.4.6 參考 "Centos7編譯安裝apache 2.4.6" 2.2. /usr/local/apache2/httpd.conf配置 2.3. /usr/local/apache2/extra/http ...
1. 需求描述
1、建立httpd服務,要求:
(1) 提供兩個基於名稱的虛擬主機:
www1.stuX.com,頁面文件目錄為/web/vhosts/www1;錯誤日誌為/var/log/httpd/www1/error_log,訪問日誌為/var/log/httpd/www1/access_log;
www2.stuX.com,頁面文件目錄為/web/vhosts/www2;錯誤日誌為/var/log/httpd/www2/error_log,訪問日誌為/var/log/httpd/www2/access_log;
(2) 通過www1.stuX.com/server-status輸出其狀態信息,且要求只允許提供賬號的用戶訪問;
(3) www1不允許192.168.1.0/24網路中的主機訪問;
2、為上面的第2個虛擬主機提供https服務,使得用戶可以通過https安全的訪問此web站點;
(1) 要求使用證書認證,證書中要求使用國家(CN),州(Beijing),城市(Beijing),組織為(jzbg);
(2) 設置部門為Ops, 主機名為www2.stuX.com;
2. 使用apache 2.4.6實現
2.1. 編譯安裝apache 2.4.6
2.2. /etc/httpd/httpd.conf配置
其餘配置預設即可
Listen 0.0.0.0:80
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authn_core_module modules/mod_authn_core.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule authz_core_module modules/mod_authz_core.so
LoadModule access_compat_module modules/mod_access_compat.so
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
LoadModule reqtimeout_module modules/mod_reqtimeout.so
LoadModule filter_module modules/mod_filter.so
LoadModule mime_module modules/mod_mime.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule env_module modules/mod_env.so
LoadModule headers_module modules/mod_headers.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule version_module modules/mod_version.so
LoadModule ssl_module modules/mod_ssl.so
LoadModule mpm_worker_module modules/mod_mpm_worker.so
LoadModule unixd_module modules/mod_unixd.so
LoadModule status_module modules/mod_status.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule dir_module modules/mod_dir.so
LoadModule alias_module modules/mod_alias.so
<IfModule unixd_module>
</IfModule>
<VirtualHost 10.207.51.53:80>
ServerName www1.stuX.com
DocumentRoot "/web/vhosts/www1"
<Location /server-status>
SetHandler server-status
AuthType Basic
AuthName "Admin Area, Please enter username and passwd"
AuthUserFile "/web/vhosts/www1-passwd"
Require user Allen Barry
</Location>
<Directory /web/vhosts/www1>
Options Indexes
AllowOverride None
<Requireall>
Require not ip 192.168.1.0/24
Require all granted
</Requireall>
</Directory>
ErrorLog /var/log/httpd/www1/error_log
CustomLog /var/log/httpd/www1/access_log combined
</VirtualHost>
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
LogLevel warn
<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
<IfModule logio_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
CustomLog "logs/access_log" common
</IfModule>
Include /etc/httpd/extra/httpd-mpm.conf
Include /etc/httpd/extra/httpd-ssl.conf
2.3. /etc/httpd/extra/httpd-ssl.conf配置
其餘配置預設即可
Listen 443 https
SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5
<VirtualHost _default_:443>
DocumentRoot "/web/vhosts/www2"
ServerName www2.stuX.com:443
ErrorLog "/var/log/httpd/www2/ssl/error_log"
TransferLog "/var/log/httpd/www2/ssl/access_log"
<Directory /web/vhosts/www2>
Options Indexes
AllowOverride None
Require all granted
</Directory>
SSLEngine on
SSLCertificateFile "/web/vhosts/certificate/stuX.httpd.crt"
SSLCertificateKeyFile "/etc/pki/CA/private/private.key"
CustomLog "/var/log/httpd/www2/ssl/access_log" \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</VirtualHost>
2.4. 測試效果
3. 使用apache 2.2.27實現
3.1. 編譯安裝apache 2.2.27
3.2. /etc/httpd/httpd.conf配置
其餘配置預設即可
Listen 0.0.0.0:80
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authn_dbm_module modules/mod_authn_dbm.so
LoadModule authn_anon_module modules/mod_authn_anon.so
LoadModule authn_dbd_module modules/mod_authn_dbd.so
LoadModule authn_default_module modules/mod_authn_default.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule authz_dbm_module modules/mod_authz_dbm.so
LoadModule authz_owner_module modules/mod_authz_owner.so
LoadModule authz_default_module modules/mod_authz_default.so
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule auth_digest_module modules/mod_auth_digest.so
LoadModule dbd_module modules/mod_dbd.so
LoadModule dumpio_module modules/mod_dumpio.so
LoadModule reqtimeout_module modules/mod_reqtimeout.so
LoadModule ext_filter_module modules/mod_ext_filter.so
LoadModule include_module modules/mod_include.so
LoadModule filter_module modules/mod_filter.so
LoadModule substitute_module modules/mod_substitute.so
LoadModule deflate_module modules/mod_deflate.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule logio_module modules/mod_logio.so
LoadModule env_module modules/mod_env.so
LoadModule expires_module modules/mod_expires.so
LoadModule headers_module modules/mod_headers.so
LoadModule ident_module modules/mod_ident.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule version_module modules/mod_version.so
LoadModule ssl_module modules/mod_ssl.so
LoadModule mime_module modules/mod_mime.so
LoadModule dav_module modules/mod_dav.so
LoadModule status_module modules/mod_status.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule asis_module modules/mod_asis.so
LoadModule info_module modules/mod_info.so
LoadModule suexec_module modules/mod_suexec.so
LoadModule cgi_module modules/mod_cgi.so
LoadModule dav_fs_module modules/mod_dav_fs.so
LoadModule vhost_alias_module modules/mod_vhost_alias.so
LoadModule negotiation_module modules/mod_negotiation.so
LoadModule dir_module modules/mod_dir.so
LoadModule imagemap_module modules/mod_imagemap.so
LoadModule actions_module modules/mod_actions.so
LoadModule speling_module modules/mod_speling.so
LoadModule userdir_module modules/mod_userdir.so
LoadModule alias_module modules/mod_alias.so
LoadModule rewrite_module modules/mod_rewrite.so
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
Include /etc/httpd/extra/httpd-ssl.conf
<VirtualHost 10.207.51.53:80>
DocumentRoot "/web/vhosts/www1"
Servername "www1.stuX.com"
ErrorLog "/var/log/httpd/www1/error_log"
CustomLog "/var/log/httpd/www1/access_log" combined
<Directory "/web/vhosts/www1">
Order deny,allow
Deny from 192.168.1.0/24
</Directory>
<Location /server-status>
SetHandler server-status
AuthType Basic
AuthName "Admin Area, Please enter username and paswd"
AuthUserFile "/web/vhosts/passwd"
Require valid-user
</Location>
</VirtualHost>
3.3. /etc/httpd/extra/httpd-ssl.conf配置
其餘配置預設即可
Listen 0.0.0.0:443 https
<VirtualHost _default_:443>
DocumentRoot "/web/vhosts/www2"
ServerName www2.stuX.com:443
ErrorLog "/var/log/httpd/www2/error_log"
TransferLog "/var/log/httpd/www2/access_log"
SSLEngine on
SSLCertificateKeyFile "/etc/pki/CA/private/private.key" ##沒有重新生成秘鑰,和配置httpd2.4.6時,使用一樣的私鑰;
SSLCertificateFile "/web/vhosts/certificate/stuX.httpd.crt" ##沒有重新申請,和配置httpd2.4.6時,使用一樣的證書;
<Directory "/web/vhosts/www2/">
Order allow,deny
Allow from all
</Directory>
CustomLog "/var/log/httpd/www2/access_log" \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</VirtualHost>
3.4. 測試效果