RHCE-网络服务实验1-实验开始

时间:2024-04-15 15:05:15

关闭安全软件

[root@server ~]# setenforce 0
[root@server ~]# systemctl stop firewalld
[root@server ~]# systemctl disable firewalld

查看一下是否关闭 

安装所需软件

[root@server ~]# yum install nginx httpd-tools -y

一、基于域名www.epenlab.com可以访问网站内容为 welcome to openlab!!!

新建一个目录

[root@server ~]# mkdir -p /www/openlab

将“welcome to openlab!!!”写入 

[root@server ~]# echo "welcome to openlab!!!" > /var/www/html/www.openlab.com

 编辑配置文件

[root@server ~]# vim /etc/nginx/nginx.conf
 
server {
              listen      80;
              server_name www.openlab.com;
              root        /www/openlab;
            }

 重启服务

[root@server ~]# systemctl restart nginx

测试

二、给该公司创建三个子界面分别显示学生信息,教学资料和缴费网站,基于www.openlab.com/student 网站访问学生信息,www.openlab.com/data网站访问教学资料www.openlab.com/money双站访问缴费网站

在Windows的hosts 中进行DNS映射,开始-搜索栏-输入windows powershell-右键单击-选择以管理员身份运行-输入notepad .\drivers\etc\hosts,回车

 此时以记事本方式打开,并添加192.168.32.147 www.openlab.com(前面是自己的ip地址)

手工配置IP地址与域名的映射关系,在系统对应的hosts文件中设置 

[root@server ~]# vim /etc/hosts
192.168.32.147 www.openlab.com/student
192.168.32.147 www.openlab.com/data
192.168.32.147 www.openlab.com/money

 使用ping命令测试

主配置文件设置

[root@server ~]# vim /etc/httpd/conf/httpd.conf

 定位到最后一行,添加如下:

<VirtualHost 192.168.32.147>
                DocumentRoot /www/student
                ServerName "www.openlab.com/student"
                <Directory /www/student>
                                AllowOverride None
                                require all granted
                </Directory>
</VirtualHost>
 
<VirtualHost 192.168.32.147>
                DocumentRoot /www/data
                ServerName "www.openlab.com/data"
                <Directory /www/data>
                                AllowOverride None
                                require all granted
                </Directory>
</VirtualHost>
 
<VirtualHost 192.168.32.147>
                DocumentRoot /www/money
                ServerName "www.openlab.com/money"
                <Directory /www/money>
                                AllowOverride None
                                require all granted
                </Directory>
</VirtualHost>

重启服务

[root@server ~]# systemctl restart httpd

在windows端打开浏览器输入域名测试 

创建教学资料子网站www.openlab.com/data、学生信息网站www.openlab.com/student、缴费网站www.openlab.com/money

[root@server ~]# mkdir /www/openlab/data
[root@server ~]# mkdir /www/openlab/student
[root@server ~]# mkdir /www/openlab/money
[root@server ~]# echo 'data' > /www/openlab/data/index.html
[root@server ~]# vim /etc/nginx/nginx.conf
//继续上一步往下写
  server {
              listen       80;
              server_name  www.openlab.com;
              root         /www/openlab;
             location      /data {
                                   alias  /www/openlab/data;
                                   index  index.html  index.htm;
                                   }
           }
[root@server ~]# systemctl restart nginx

三、学生信息网站只有song和tian两人可以访问,其他用户不能访问

编辑httpd用户主页配置,设置对应参数

[root@server ~]# vim /etc/httpd/conf.d/userdir.conf

新增2个普通账户,切换到普通账户,进入家目录,重启服务

[root@server ~]# useradd song
[root@server ~]# passwd song
passwd:所有的身份验证令牌已经成功更新。
[root@server ~]# useradd tian
[root@server ~]# passwd tian 
passwd:所有的身份验证令牌已经成功更新。
[root@server ~]# su song             // 切换账户 
[t1@server root]$ cd /home/song          // 进入song账户的家目录 
[t1@server ~]$ mkdir public_html      // 新建用于存储网页数据的目录public_html 
// 使用xftp将zy目录内容所有网页文件上传到/home/song/public_html目录中 
[t1@server ~]$ chmod -Rf 755 /home/song   //设置权限 
[t1@server ~]$ ll       // 查看权限 
 
[root@server ~]# su tian      //切换账户 
[t1@server root]$ cd /home/tian          //进入tian账户的家目录 
[t1@server ~]$ mkdir public_html     //新建用于存储网页数据的目录public_html 
// 使用xftp将zy目录内容所有网页文件上传到/home/tian/public_html目录中 
[t1@server ~]$ chmod -Rf 755 /home/tian      // 设置权限 
[t1@server ~]$ ll        //查看权限 
[t2@server ~]$ su root # 切换到root账户 
密码: 
[root@server ~]# systemctl restart httpd # 重启服务

 安装mod_ssl

[root@server ~]# yum install mod_ssl  -y

 在/etc/pki/tls/private目录下生成私钥文件

[root@server ~]# cd /etc/pki//tls/private
[root@server private]# ls
localhost.key
[root@server private]# openssl genrsa -aes128 2048 > money.key
Generating RSA private key, 2048 bit long modulus (2 primes)
........................+++++
..................................+++++
e is 65537 (0x010001)
Enter pass phrase:                //设置私钥文件加密的密码
Verifying - Enter pass phrase:         //重输密码
[root@server private]# ls
localhost.key  money.key

 在/etc/pki/tls/certs目录下新建证书,重启服务

[root@server ~]# openssl req -utf8 -new -key /etc/nginx/money.key -x509 -days 365 -out /etc/nginx/money.crt                //制作证书
Enter pass phrase for /etc/nginx/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) [AU]:86           //国家编号
State or Province Name (full name) [Some-State]:ningxia    //省级名称
Locality Name (eg, city) []:yinchuan                       //市级名称
Organization Name (eg, company) [Internet Widgits Pty Ltd]:openlab     //组织名称
Organizational Unit Name (eg, section) []:RHCE                         //部门名称
Common Name (e.g. server FQDN or YOUR name) []:server                  //用户名称
Email Address []:and@qq.com                                            //邮箱
[root@server ~]# cd /etc/nginx
[root@server nginx]# cp money.key money.key.org
[root@server nginx]# openssl rsa -in money.key.org -out money.key
Enter pass phrase for money.key.org:
writing RSA key
[root@server certs]# systemctl restart httpd