HTTP实验:分别使用httpd-2.2和httpd-2.4实现
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. 测试效果