作业题
1.要求搭建web服务器,能够访问到网页内容为“小胖,你咋这么胖呢!”
vim /etc/httpd/conf.d/vhosts.conf
输入:进入命令模式
使用 r /usr/share/doc/httpd/httpd-vhosts.conf 读取配置文件并修改
<Directory />
AllowOverride none
Require all denied
</Directory>
<Directory "/www">
AllowOverride None
# Allow open access:
Require all granted
</Directory>
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
[root@bogon ~]# cd /var/www/html
[root@bogon html]# echo 小胖,你咋这么胖呢!> index.html
[root@bogon ~]# systemctl start httpd
[root@bogon ~]# systemctl stop firewalld
[root@bogon ~]# setenforce 0
测试结果
2.要求搭建web服务器,创建基于域名的虚拟主机,能够使用www.xiaopang.com和www.dapang.com访问各自的网站网站存放路径分别为/xiaopang和/dapang,内容自定。
[root@bogon ~]# vim /etc/httpd/conf.d/vhosts.conf ##修改配置文件
#<VirtualHost 192.168.248.130.:80>
# DocumentRoot "/openlab/xiaopang"
# ServerName www.xaiopangzhi.com
# ErrorLog "/var/log/httpd/dummy-130.example.com-error_log"
# CustomLog "/var/log/httpd/dummy-130.example.com-access_log" common
#</VirtualHost>
#<VirtualHost 192.168.248.130:80>
# DocumentRoot "/openlab/dapang"
# ServerName www.dapangzhi.com
# ErrorLog "/var/log/httpd/dummy-130.example.com-error_log"
# CustomLog "/var/log/httpd/dummy-130.example.com-access_log" common
#</VirtualHost>
#<Directory /openlab>
# AllowOverride none
# Require all granted
#</Directory>
修改完毕
[root@bogon openlab]# mkdir /openlab/{xiaopang,dapang} -pv
mkdir: created directory '/openlab'
mkdir: created directory '/openlab/xiaopang'
mkdir: created directory '/openlab/dapang'
[root@bogon openlab]# cd /openlab
[root@bogon openlab]# ll
total 0
drwxr-xr-x. 2 root root 6 Mar 23 21:15 dapang
drwxr-xr-x. 2 root root 6 Mar 23 21:15 xiaopang
[root@bogon openlab]# ll dapang
total 0
[root@bogon openlab]# ll xiaopang
total 0
[root@bogon openlab]# echo 大胖你真瘦 > /openlab/dapang/index.html
[root@bogon openlab]# echo 小胖你真瘦 > /openlab/xaiopang/index.html
-bash: /openlab/xaiopang/index.html: No such file or directory
[root@bogon openlab]# echo 小胖你真瘦 > /openlab/xiaopang/index.html
[root@bogon openlab]# systemctl restart httpd
[root@bogon openlab]# systemctl stop firewalld
[root@bogon openlab]# systemctl restart httpd
测试结果
3.创建 虚拟目录真实物理位置在/usr/local/hehe,内容自定
修改配置文件
<VirtualHost 192.168.248.130:80>
DocumentRoot "/openlab/130"
Alias /file /usr/local/hehe
ServerName 192.168.248.130
Alias /3w /www
</VirtualHost>
<Directory /openlab>
AllowOverride none
Require all granted
</Directory>
<Directory "/www">
AllowOverride None
# Allow open access:
Require all granted
</Directory>
[root@bogon openlab]# mkdir -pv /usr/local/hehe
mkdir: created directory '/usr/local/hehe'
[root@bogon openlab]# cd /usr/local
[root@bogon local]# mkdir /hehe
[root@bogon local]# echo xunimulu > /usr/local/hehe/index.html
4.创建虚拟目录真实物理位置在 /usr/local/maomao,内容自定,但允许abc和xyz用户通过密码访问。
配置文件
<VirtualHost 192.168.248.130:80>
DocumentRoot "/openlab/130"
Alias /file /usr/local/hehe
ServerName 192.168.248.130
Alias /3w /www
</VirtualHost>
<Directory /openlab>
AllowOverride none
Require all granted
</Directory>
<Directory "/www">
AllowOverride None
# Allow open access:
Require all granted
</Directory>
<Directory /www>
AuthType Basic
AuthName "Please login:"
AuthuserFile /etc/httpd/userfile
Require user abc xyz
</Directory>
[root@bogon www]# htpasswd -c /etc/httpd/userfile abc
New password:
Re-type new password:
Adding password for user abc
[root@bogon www]# htpasswd -c /etc/httpd/userfile xyz
New password:
Re-type new password:
Adding password for user xyz
[root@bogon www]# systemcti restart httpd
bash: systemcti: command not found...
[root@bogon www]# systemctl restart httpd
测试结果:
登陆界面
输入用户名密码后