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),组织为(MageEdu);
(2) 设置部门为Ops, 主机名为www2.stuX.com;
2. 使用apache 2.4.6实现
2.1. 编译安装apache 2.4.6
2.2. /usr/local/apache2/httpd.conf配置
ServerRoot "/usr/local/apache2"
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>
DocumentRoot "/usr/local/apache2/htdocs"
<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. /usr/local/apache2/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. 测试效果