目录
1、配置 /etc/httpd/conf.d/vhosts.conf(首先确保安装httpd)
3、写入相应内容到相应目录下的 index.hcml文件中(网页显示的内容)
4、配置缴费网站(www.openlab.com/money)基于https访问
(3)修改 /etc/httpd/conf.d/vhosts.conf 下的关于www.openlab.com/money部分
1、在缓存文件 /etc/hosts 中添加 IP 与域名信息
3、只有 song 和 tian 可以访问www.openlab.com/student,其他用户不能访问
1、httpd主配置文件在 /etc/httpd/conf/httpd.conf
2、额外的参数文件 /etc/httpd/conf.d/*.conf
3、设置默认访问apache欢迎界面的配置文件 /etc/httpd/conf.d/welcome.conf
4、apache欢迎界面的具体文件 /usr/share/httpd/noindex/index.html
5、默认的首页所在目录/var/www/html/,当输入网址时所显示的数据,就是放在这个目录当中的首页文件(默认为index.html)
6、自己定义的静态页面是在/var/www/html目录,因为主配置文件中DocumentRoot "/var/www/html" #网页文件存放的目录
7、静态网页的名字是index.html 是因为主配置文件中目录模块配置的目录索引,索引文件名为index.html
#加载一个目录模块
DirectoryIndex index.html
8、默认给一些可执行的CGI(网页程序)程序放置的目录/var/www/cgi-bin/,当输入网址/cgi-bin/时所显示的数据所在
9、默认的Apache日志文件都放在/var/log/httpd/
1.基于域名[www.openlab.com](http://www.openlab.com)可以访问网站内容为 welcome to openlab!!!
2.给该公司创建三个子界面分别显示学生信息,教学资料和缴费网站[www.openlab.com/student(http://www.openlab.com/student) 网站访问学生信息
[www.openlab.com/data](http://www.openlab.com/data)网站访问教学资料
[www.openlab.com/money](http://www.openlab.com/money网站访问缴费网站)3.要求(1)学生信息网站只有song和tian两人可以访问,其他用户不能访问
(2)访问缴费网站实现数据加密基于https访问
- [root@server ~]# vim /etc/httpd/conf.d/vhosts.conf
-
-
192.168.225.140:80> - DocumentRoot /www/openlab
- ServerName www.openlab.com
-
192.168.225.140:80> - DocumentRoot /www/openlab/student
- ServerName www.openlab.com/student
-
192.168.225.140:80> - DocumentRoot /www/openlab/data
- ServerName www.openlab.com/data
-
192.168.225.140:80> - DocumentRoot /www/openlab/money
- ServerName www.openlab.com/money
-
- AllowOverride none
- Require all granted
-
- //用户认证
- AuthType Basic //基本认证类型
- AuthName "Please login:" //提示信息
- AuthUserFile /etc/httpd/userfile //用户认证文件的用户名和密码指定的文件所在位置
- Require user song //指定哪个用户可以访问服务器
- Require user tian
-
- [root@server ~]# mkdir /www/openlab/{student,data,money} -pv
- mkdir: created directory '/www'
- mkdir: created directory '/www/openlab'
- mkdir: created directory '/www/openlab/student'
- mkdir: created directory '/www/openlab/data'
- mkdir: created directory '/www/openlab/money'
-
- [root@server ~]# htpasswd -c /etc/httpd/userfile song
- New password:
- Re-type new password:
- Adding password for user song
- [root@server ~]# htpasswd /etc/httpd/userfile tian
- New password:
- Re-type new password:
- Adding password for user tian
- [root@server ~]# htpasswd /etc/httpd/userfile wu
- New password:
- Re-type new password:
- Adding password for user wu
- [root@server ~]# echo welcome to openlab > /www/openlab/index.html
- [root@server ~]# echo student information > /www/openlab/student/index.html
- [root@server ~]# echo teaching information > /www/openlab/data/index.html
- [root@server ~]# echo payment information > /www/openlab/money/index.html
[root@server ~]# yum install mod_ssl -y
- [root@server ~]# vim /etc/httpd/conf.d/ssl.conf
-
443> - SSLEngine on //开启ssl认证访问
- SSLCertificateFile /etc/pki/tls/certs/localhost.crt //指定证书路径
- SSLCertificateKeyFile /etc/pki/tls/private/localhost.key //指定私钥文件路径
- [root@server ~]# openssl req -newkey rsa:4096 -nodes -sha256 -keyout /etc/pki/tls/private/openlab.key -x509 -days 365 -out /etc/pki/tls/certs/openlab.crt
- Generating a RSA private key
- ..........................................................................................++++
- .............................................................++++
- writing new private key to '/etc/pki/tls/private/openlab.key'
- -----
- You are about to be asked to enter information that will be incorporated
- into your certificate request.
- What you are about to enter is what is called a Distinguished Name or a DN.
- There are quite a few fields but you can leave some blank
- For some fields there will be a default value,
- If you enter '.', the field will be left blank.
- -----
- Country Name (2 letter code) [XX]:86
- State or Province Name (full name) []:shannxi
- Locality Name (eg, city) [Default City]:xi'an
- Organization Name (eg, company) [Default Company Ltd]:openlab
- Organizational Unit Name (eg, section) []:ce
- Common Name (eg, your name or your server's hostname) []:xixi
- Email Address []:ada
- [root@server ~]# ll /etc/pki/tls/private/
- total 4
- -rw-------. 1 root root 3272 Sep 6 20:45 openlab.key
- [root@server ~]# ll /etc/pki/tls/certs
- total 4
- lrwxrwxrwx. 1 root root 49 Jun 17 2021 ca-bundle.crt -> /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
- lrwxrwxrwx. 1 root root 55 Jun 17 2021 ca-bundle.trust.crt -> /etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt
- -rw-r--r--. 1 root root 2057 Sep 6 20:50 openlab.crt
- [root@server ~]# vim /etc/httpd/conf.d/vhosts.conf
-
192.168.225.140:443> //修改端口为443 - DocumentRoot /www/openlab/money
- ServerName www.openlab.com/money
- SSLEngine on //开启ssl认证访问
- SSLCertificateFile /etc/pki/tls/certs/openlab.crt //指定证书路径
- SSLCertificateKeyFile /etc/pki/tls/private/openlab.key //指定私钥文件路径
[root@server ~]# systemctl restart httpd
- [root@server ~]# vim /etc/hosts
-
- 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
- ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
- 192.168.225.140 www.openlab.com
- [root@server ~]# curl www.openlab.com
- welcome to openlab
- [root@server ~]# curl www.openlab.com/student/ -u song
- Enter host password for user 'song':
- student information
- [root@server ~]# curl www.openlab.com/student/ -u tian
- Enter host password for user 'tian':
- student information
- [root@server ~]# curl www.openlab.com/student/ -u wu
- Enter host password for user 'wu':
- "-//IETF//DTD HTML 2.0//EN">
401 Unauthorized //请求未经授权Unauthorized
This server could not verify that you
- are authorized to access the document
- requested. Either you supplied the wrong
- credentials (e.g., bad password), or your
- browser doesn't understand how to supply
- the credentials required.
- [root@server ~]# curl www.openlab.com/data/
- teaching information
