综合练习:请给openlab搭建web网站 网站需求:
要求 (1)学生信息网站只有song和tian两人可以访问,其他用户不能访问。 (2)访问缴费网站实现数据加密基于https访问。
1题,2题与3题的一小问做如下配置
[root@localhost ~]#mkdir -pv /www/openlab/{student,data,money}
[root@localhost ~]#echo student > /www/openlab/student/index.html
[root@localhost ~]#echo data > /www/openlab/data/index.html
[root@localhost ~]#echo money > /www/openlab/money/index.html
[root@localhost ~]#sentenforce 0
[root@localhost ~]#htpasswd -c /etc/httpd/mymima song
[root@localhost ~]#htpasswd /etc/httpd/mymima tian
[root@localhost ~]#vim /etc/hosts
192.168.196.100 www.openlab.com
[root@localhost ~]# vim /etc/httpd/conf.d/openlab.conf
<VirtualHost 192.168.196.100:80>
DocumentRoot /www/openlab
ServerName www.openlab.com
alias /data /www/openlab/data
alias /student /www/openlab/student
alias /money /www/openlab/money
ErrorLog "/var/log/httpd/openlab-error_log"
CustomLog "/var/log/httpd/openlab-access_log" common
</VirtualHost>
<directory /www/openlab>
allowoverride none
require all granted
</directory>
<directory /www/openlab/student>
authtype basic
authname "please login:"
authuserfile /etc/httpd/mymima
require user song tian
</directory>
[root@localhost ~]#systemctl restart httpd
[root@localhost ~]# curl https://www.openlab.com
welcome to openlab
[root@localhost ~]# curl https://www.openlab.com/data/
data
[root@localhost ~]# curl https://www.openlab.com/student/ -u tian:123
student
对于3题的第2问,只需修改和增加以下配置。
[root@www conf.d]# yum install mod_ssl httpd -y
[root@www conf.d]# cd /etc/pki/tls/certs/
[root@www certs]# openssl genrsa -aes128 2048 > openlab.key
[root@www certs]# openssl req -utf8 -new -key openlab.key -x509 -days 100 -out openlab.crt
[root@localhost ~]# cat /etc/httpd/conf.d/openlab.conf
#<VirtualHost 192.168.196.100:80>
# DocumentRoot /www/openlab
# ServerName www.openlab.com
# alias /data /www/openlab/data
# alias /student /www/openlab/student
# alias /money /www/openlab/money
# ErrorLog "/var/log/httpd/openlab-error_log"
# CustomLog "/var/log/httpd/openlab-access_log" common
#</VirtualHost>
<VirtualHost 192.168.196.100:443>
DocumentRoot /www/openlab
ServerName www.openlab.com
alias /data /www/openlab/data
alias /student /www/openlab/student
alias /money /www/openlab/money
ErrorLog "/var/log/httpd/openlab-error_log"
CustomLog "/var/log/httpd/openlab-access_log" common
sslengine on
SSLCertificateFile /etc/pki/tls/certs/openlab.crt
SSLCertificateKeyFile /etc/pki/tls/certs/openlab.key
</VirtualHost>
<directory /www/openlab>
allowoverride none
require all granted
</directory>
<directory /www/openlab/student>
authtype basic
authname "please login:"
authuserfile /etc/httpd/mymima
require user song tian
</directory>
[root@localhost ~]# curl -k https://www.openlab.com/student/ -u tian:123
student
[root@localhost ~]# curl -k https://www.openlab.com/data/
data