(1)www.X.com,页面文件目录为/web/vhosts/x;错误日志为/var/log/httpd/x.err,访问日志为/var/log/httpd/x.access
(2)www.Y.com,页面文件目录为/web/vhosts/y;错误日志为/var/log/httpd/www2.err,访问日志为/var/log/httpd/y.access
(3)为两个虚拟主机创建各自的主页文件index.html,内容分别为其对应的主机名
(4)经过www.X.com/server-status输出httpd工做状态相关信息html
#增长两条HOST 解析 vim /etc/hosts 192.168.120.130 www.x.com www.y.com vim /etc/httpd/conf.d/vhost.conf <VirtualHost *:80> #虚拟主机的别名;可屡次使用,目前是不起做用的 ServerName www.x.com #指定根目录 DocumentRoot "/web/vhosts/x" #错误日志 ErrorLog "logs/x.err" #访问日志 TransferLog "logs/x.access" <Location /server-status> SetHandler server-status Order deny,allow Deny from all Allow from 192.168 </Location> </VirtualHost> <VirtualHost *:80> #虚拟主机的别名;可屡次使用,目前是不起做用的 ServerName www.y.com #指定根目录 DocumentRoot "/web/vhosts/y" #错误日志 ErrorLog "logs/www2.err" #访问日志 TransferLog "logs/y.access" </VirtualHost> <Directory "/web/vhosts"> Order allow,deny Allow from all </Directory> 若是是Centos6 必定要把主配置文件中的NameVirtualHost 打开,或者在这个配置文件中加上如下配置 NameVirtualHost *:80 不然没法启动虚拟主机!!!!
二、为上面的第2个虚拟主机提供https服务,使得用户能够经过https安全的访问此web站点web
(1)要求使用证书认证,证书中要求使用的国家(CN)、州(Beijing)、城市(Beijing)和组织(MageEdu)
(2)设置部门为Ops,主机名为www.Y.com,邮件为admin@Y.comapache
省略步骤 参考 http 高级配置 笔记中的步骤 注意:ssl会话只能基于IP建立,这意味着若是服务器仅有一个IP,那么仅为一个虚拟主机提供https服务
一、创建httpd服务,要求:vim
(1) 提供两个基于名称的虚拟主机:
www.a.com
页面文件目录为/web/vhosts/www1
错误日志为/var/log/httpd/www1/error_log
访问日志为/var/log/httpd/www1/access_log安全
www.b.com 页面文件目录为/web/vhosts/www2 错误日志为/var/log/httpd/www2/error_log 访问日志为/var/log/httpd/www2/access_log
(2) 经过www.a.com/server-status输出其状态信息,且要求只容许提供帐号的用户访问服务器
(3) www.a.com不容许192.168.1.0/24网络中的主机访问网络
#一次性编译安装 apr + apr-util + http 不须要分三次来 #把三个压缩包都解压了 yum groupinstall Development Tools,Server yum install openssl-devel expat-devel pcre-devel useradd -r -g 80 apache useradd -r -s /sbin/nologin -u 80 -g 80 apache tar xvg apr apr-util httpd mv apr-1.6.3 http/srclib/apr mv apr-util-1.6.1 http/srclib/apr-util cd httpd-2.4.27/ ./configure --prefix=/app/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-included-apr --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork make && make install #添加变量 echo PATH=/app/httpd24/bin:$PATH > /etc/profile.d/httpd.sh #启动服务 apachectl
#建立验证文件 htpasswd -s -c .httpuser ddz htpasswd -s .httpuser wang #虚拟主机设置 vim /app1/httpd24/conf/http.conf Include conf/conf.d/*.conf vim /app1/httpd24/conf/conf.d/vhost.conf <VirtualHost *:80> ServerName www.a.com DocumentRoot "/web/vhosts/www1" ErrorLog "/var/log/httpd/www1/error_log" TransferLog "/var/log/httpd/www1/access_log" <Location /server-status> SetHandler server-status AuthType Basic AuthName "Please Input Accout!!!" AuthUserFile "/appl/httpd24/conf/conf.d/.httpuser" Require user ddz,wang </Location> <Directory "/web/vhosts/www1"> <RequireAll> Require all granted Require not ip 192.168.1. </RequireAll> </Directory> </VirtualHost> <VirtualHost *:80> ServerName www.b.com DocumentRoot "/web/vhosts/www2" ErrorLog "/var/log/httpd/www2/error_log" TransferLog "/var/log/httpd/www2/access_log" </VirtualHost>
二、为上面的第2个虚拟主机提供https服务,使得用户能够经过https安全的访问此web站点app
(1) 要求使用证书认证,证书中要求使用国家(CN),州(Beijing),城市(Beijing),组织为(MageEdu)ui
(2) 设置部门为Ops, 主机名为www.b.com日志
若是是编译安装,安装完模块,须要移动配置文件 yum install mod_ssl cp /etc/httpd/conf.d/ssl.conf /appl/httpd24/conf/conf.d/ssl.conf 开启模块 vim httpd.conf LoadModule ssl_module modules/mod_ssl.so LoadModule socache_shmcb_module modules/mod_socache_shmcb.so 配置SSL文件 <VirtualHost 192.168.120.131:443> DocumentRoot "/web/vhosts/www1" ServerName www.a.com SSLCertificateFile /appl/httpd24/certs/httpd.crt SSLCertificateKeyFile /appl/httpd24/certs/httpd.key SSLCertificateChainFile /etc/pki/CA/cacert.pem 使用了https的话,记得把刚才vhost里面的虚拟主机配置移动到ssl中,不然没法识别。 ssl 是能够配置多个的