RHCE第四天的两个案例:
[root@localhost ~]# vim /etc/httpd/conf.d/vhosts.conf
#以下的是openlab网站
<VirtualHost 192.168.72.105:80>
DocumentRoot /www/openlab
alias /student /openlab/student/
alias /data /openlab/data/
alias /money /openlab/money/
ServerName www.openlab.com #这里要去改Windows中的hosts文件
</VirtualHost>
<Directory /openlab>
AllowOverride none
Require all granted
</Directory>
[root@localhost ~]# systemctl restart httpd
#创建相应文件夹
[root@localhost ~]# mkdir /www/openlab
[root@localhost ~]# echo "welcome to openlab" > /www/openlab/index.html
[root@localhost ~]# cd /
[root@localhost /]# mkdir openlab
[root@localhost /]# cd openlab/
[root@localhost openlab]# mkdir student data money
[root@localhost openlab]# echo this is data > data/index.html
[root@localhost openlab]# echo this is money > money/index.html
[root@localhost openlab]# echo this is student > student/index.html
#要求:学生信息只有song和tian两人可以访问:
[root@localhost ~]# vim /etc/httpd/conf.d/vhosts.conf
<Directory /openlab/student>
Authtype Basic
AuthName "openlab"
AuthUserFile /etc/httpd/users
Require user song tian
</Directory>
#添加song和tian用户
[root@localhost ~]# htpasswd /etc/httpd/users song
New password:
Re-type new password:
Adding password for user song
[root@localhost ~]# htpasswd /etc/httpd/users tian
New password:
Re-type new password:
Adding password for user tian
#要求:访问缴费网站实现数据加密基于https访问
[root@localhost ~]# vim /etc/httpd/conf.d/vhosts.conf
<VirtualHost 192.168.72.105:443>
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/openlab.crt
SSLCertificateKeyFile /etc/pki/tls/private/openlab.key
DocumentRoot /www/openlab
alias /money /openlab/money/
ServerName www.openlab.com
</VirtualHost>
#最后restart httpd
[root@localhost ~]# systemctl restart httpd
总结一下vhosts.conf:
[root@localhost ~]# setenforce 0
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# vim /etc/httpd/conf.d/vhosts.conf
#以下的是不同部门间的文件传输
Listen 10000
<VirtualHost 192.168.72.104:10000>
DocumentRoot /www/FileSharing
ServerName 192.168.72.104
alias /tec /FileSharing/Technology
alias /dev /FileSharing/Development
</VirtualHost>
<Directory /FileSharing/Technology>
Options +Indexes
Authtype Basic
AuthName "share"
AuthUserFile /etc/httpd/users
Require user tecuser
</Directory>
<Directory /FileSharing/Development>
Options +Indexes
Authtype Basic
AuthName "share"
AuthUserFile /etc/httpd/users
Require user devuser
</Directory>
#添加用户
[root@localhost ~]# htpasswd /etc/httpd/users tecuser
New password:
Re-type new password:
Adding password for user tecuser
[root@localhost ~]# htpasswd /etc/httpd/users devuser
New password:
Re-type new password:
Adding password for user devuser
[root@localhost ~]# cd /www
[root@localhost www]# mkdir FileSharing
[root@localhost www]# echo "this is FileSharing" > FileSharing/index.html
[root@localhost www]# cd /
[root@localhost /]# mkdir -p FileSharing/Technology/{file1,file2,file3,file4}
[root@localhost /]# mkdir -p FileSharing/Development/{file1,file2,file3,file4}
[root@localhost /]# cd
[root@localhost ~]# systemctl restart httpd
打开浏览器看效果: