网站的搭建

实验要求:

实验要求一:搭建主站www.openlab.com

 第一步:安装httpd 和mod_ssl

 第二步:进行域名映射  vim  /etc/hosts

 第三步:创建网页目录并写入数据

[root@server ~]# mkdir -p /www/openlab
[root@server ~]# echo 'welcome to openlab' > /www/openlab/index.html
[root@server ~]# ls /www/openlab
index.html

第四步:编辑主配置文件

[root@server ~]# vim /etc/httpd/conf/httpd.conf 
<virtualhost 192.168.253.128>
        documentroot    /www/openlab
        servername      'www.openlab.com'
        <directory /www/openlab>
                allowoverride  none
                require all granted
        </directory>
</virtualhost>

第五步重启服务并测试

[root@server ~]# systemctl restart httpd

 实验要求一:搭建子站

1.搭建教学资www.openlab.com/data

第一步:创建子网站文件,并写入数据

[root@server ~]# mkdir -p /www/openlab/data
[root@server ~]# echo 'data' > /www/openlab/data/index.html

第二步:编辑主配置文件

<virtualhost 192.168.253.128>
        documentroot    /www/openlab/data
        alias   /data   /www/openlab/data
        servername      'www.openlab.com'
        <directory /www/openlab/data>
                allowoverride  none
                require all granted
        </directory>
</virtualhost>

第三步重启服务测试

[root@server ~]# systemctl restart httpd

 2.搭建学生信息子网站

第一步:创建学生子网站目录并写入信息

[root@server ~]# mkdir -p /www/openlab/student
[root@server ~]# echo 'student' > /www/openlab/student/index.html

第二步:创建用户并设置密码

[root@server ~]# passwd song
更改用户 song 的密码 。
新的密码: 
无效的密码: 密码少于 8 个字符
重新输入新的密码: 
passwd:所有的身份验证令牌已经成功更新。
[root@server ~]# useradd tian
[root@server ~]# passwd tian
更改用户 tian 的密码 。
新的密码: 
无效的密码: 密码少于 8 个字符
重新输入新的密码: 
passwd:所有的身份验证令牌已经成功更新。

第三步:新建密码存储文件

[root@server ~]# htpasswd -c /etc/httpd/passwd song
New password: 
Re-type new password: 
Adding password for user song
[root@server ~]# htpasswd  /etc/httpd/passwd tian
New password: 
Re-type new password: 
Adding password for user tian

第四步:编辑主配置文件

<directory /www/openlab/student>
        authuserfile    /etc/httpd/passwd
        authname        'student'
        authtype        basic
        require         user    song tian
</directory>

第五步重启服务并测试

[root@server ~]# systemctl restart httpd

 

 3.搭建缴费网站www.openlab.com/money

第一步:创建缴费网站目录

[root@server ~]# mkdir -p /www/openlab/money
[root@server ~]# echo 'money' > /www/openlab/money/index.html

第二步:创建私钥

[root@server ~]# echo 'money' > /www/openlab/money/index.html
[root@server ~]# openssl genrsa -aes128 2048 > /etc/pki/tls/private/money.key
Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:

 第三步:创建证书

[root@server ~]# openssl req -utf8 -new -key /etc/pki/tls/private/money.key -x509 -days 365 -out  /etc/pki/tls/certs/money.crt
Enter pass phrase for /etc/pki/tls/private/money.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) []:SX
Locality Name (eg, city) [Default City]:xi'an
Organization Name (eg, company) [Default Company Ltd]:RHCE                               
Organizational Unit Name (eg, section) []:RHCE
Common Name (eg, your name or your server's hostname) []:NODE1
Email Address []:123@qq.com   

第四步:编辑主配置文件

<virtualhost 192.168.253.128:443>
        sslengine       on
        documentroot    /www/openlab/money
        alias   /money  /www/openlab/money
        SSLCertificateFile      /etc/pki/tls/certs/money.crt
        SSLCertificateKeyFile   /etc/pki/tls/private/money.key
        servername      'www.openlab.com'
        <directory /www/openlab/money>
                allowoverride  none
                require all granted
        </directory>
</virtualhost>

第五步:重启服务并测试

[root@server ~]# systemctl restart httpd
🔐 Enter TLS private key passphrase for www.openlab.com:443 (RSA) : ******