RHCE-网络服务实验1

要求:

实验开始

关闭安全软件

复制代码
[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
相关推荐
Johny_Zhao9 小时前
OpenClaw安装部署教程
linux·人工智能·ai·云计算·系统运维·openclaw
YuMiao1 天前
gstatic连接问题导致Google Gemini / Studio页面乱码或图标缺失问题
服务器·网络协议
chlk1232 天前
Linux文件权限完全图解:读懂 ls -l 和 chmod 755 背后的秘密
linux·操作系统
舒一笑2 天前
Ubuntu系统安装CodeX出现问题
linux·后端
改一下配置文件2 天前
Ubuntu24.04安装NVIDIA驱动完整指南(含Secure Boot解决方案)
linux
碳基沙盒2 天前
OpenClaw 多 Agent 配置实战指南
运维
深紫色的三北六号2 天前
Linux 服务器磁盘扩容与目录迁移:rsync + bind mount 实现服务无感迁移(无需修改配置)
linux·扩容·服务迁移
SudosuBash2 天前
[CS:APP 3e] 关于对 第 12 章 读/写者的一点思考和题解 (作业 12.19,12.20,12.21)
linux·并发·操作系统(os)
哈基咪怎么可能是AI3 天前
为什么我就想要「线性历史 + Signed Commits」GitHub 却把我当猴耍 🤬🎙️
linux·github
十日十行4 天前
Linux和window共享文件夹
linux