RHCE第二次作业

文章详细描述了如何配置Nginx以支持多个子域名访问,包括限制学生信息和缴费网站的权限,以及设置HTTPS加密和NFS共享,包括文件权限管理和上传功能。
摘要由CSDN通过智能技术生成

1.基于域名[www.openlab.com](http://www.openlab.com)可以访问网站内容为 welcome to openlab!!!

	#关闭防火墙
	 
	[root@server ~]# systemctl stop firewalld
	[root@server ~]# setenforce 0
	 
	#下载nginx软件包
	[root@server ~]#yum install nginx -y
	 
	#编辑配置文件
	[root@server ~]# vim /etc/nginx/conf.d/test_name.conf
	server{
	        listen 192.168.129.133:80;
	        root /www/name/openlab;
	        server_name www.openlab.com;
	        location / {
	        }
	}

	#写入网站内容
	[root@server ~]# vim /www/name/openlab/index.html
    welcome to openlab!!!
	 
	#创建相应需要目录
	[root@server ~]# cd /etc/nginx
	[root@server nginx]# cd
	[root@server ~]# mkdir -pv /www/name/openlab
	mkdir: 已创建目录 '/www'
	mkdir: 已创建目录 '/www/name'
	mkdir: 已创建目录 '/www/name/openlab'
	 
	 
	#添加本地域名
	[root@server ~]# vim /etc/hosts
	192.168.129.133 www.openlab.com

    #重启nginx
    [root@localhost ~]# systemctl restart nginx

    #测验
    [root@server ~]# curl 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)网站访问教学资料,网站访问缴费网站(http://www.openlab.com/money网站访问缴费网站)。

        要求 (1)学生信息网站只有song和tian两人可以访问,其他用户不能访问。

                (2)访问缴费网站实现数据加密基于https访问。

#配置文件
[root@server ~]#vim /etc/nginx/conf.d/test1_name.conf
server{
        listen 192.168.1.130:80;
        root /www/name/openlab;
        server_name www.openlab.com;
        location /student{
                index index.html;
                auth_basic on;
                auth_basic_user_file /etc/nginx/users;
        }
 
 
        location /data{
 
        }
 
}
 
 
#根据配置文件创建相应目录
[root@server ~]# cd /www/name/openlab
[root@server openlab]# mkdir -pv {student,data,money}
mkdir: 已创建目录 'student'
mkdir: 已创建目录 'data'
mkdir: 已创建目录 'money'
 
#写入内容
[root@server openlab]# echo this is student > /www/name/openlab/student/index.html
[root@server openlab]# echo this is data > /www/name/openlab/data/index.html
[root@server openlab]# echo this is money > /www/name/openlab/money/index.html
 
 
#安装httpd包
[root@server ~]# yum install httpd-tools
 
#用户认证
[root@server ~]# htpasswd -c /etc/nginx/users song
New password:
Re-type new password:
Adding password for user song
[root@server ~]# htpasswd -c /etc/nginx/users tian
New password:
Re-type new password:
Adding password for user tian
 
配置https文件
[root@server ~]# vim /etc/nginx/conf.d/test_https.conf
server{
        listen 192.168.1.130:443 ssl;
        root /www/name/openlab;
        server_name www.openlab.com;
        ssl_certificate /etc/pki/tls/certs/openlab.crt;
        ssl_certificate_key /etc/pki/tls/private/openlab.key;
        location /money{
        }
}
 
#进行https访问配置
[root@server ~]# openssl genrsa -out /etc/pki/tls/private/openlab.key
[root@server ~]# openssl req -utf8 -new -key /etc/pki/tls/private/openlab.key -x509 -days 365 -out /etc/pki/tls/certs/openlab.crt
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]:xi'an
Locality Name (eg, city) []:shanxi
Organization Name (eg, company) [Internet Widgits Pty Ltd]:open
Organizational Unit Name (eg, section) []:ce
Common Name (e.g. server FQDN or YOUR name) []:1111
Email Address []:admin

[root@server ~]# systemctl restart nginx
[root@server ~]# curl https://www.openlab.com/money/
curl: (60) SSL certificate problem: self-signed certificate
More details here: https://curl.se/docs/sslcerts.html
 
curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.


#测试
[root@server ~]# curl www.openlab.com/student/ -u song
Enter host password for user 'song':
this is student
 
[root@server ~]# curl https://www.openlab.com/money/ -k
this money

[root@server ~]# curl www.openlab.com/data
this is data

3.架设一台NFS服务器,并按照以下要求配置

       要求  1、开放/nfs/shared目录,供所有用户查询资料

                2、开放/nfs/upload目录,为192.168.xxx.0/24网段主机可以上传目录,

                     并将所有用户及所属的组映射为nfs-upload,其UID和GID均为210

               3、将/home/tom目录仅共享给192.168.xxx.xxx这台主机,并只有用户tom可以完全访问                        该目录

服务端
 
#创建需要目录
 
[root@server ~]# mkdir -pv /nfs/shared /nfs/upload /home/tom
mkdir: 已创建目录 '/nfs'
mkdir: 已创建目录 '/nfs/shared'
mkdir: 已创建目录 '/nfs/upload'
mkdir: 已创建目录 '/home/tom'
 
启用nfs服务
[root@server ~]# systemctl start nfs-server.service
#创建文件
[root@server ~]# touch /nfs/shared/{a..d}
[root@server ~]# touch /nfs/upload/{1..4}
 
#编辑配置文件
[root@server ~]# vim /etc/exports
/nfs/shared   *(ro)
/nfs/upload   192.168.1.0/24(rw,no_all_squash,anonuid=210,anongid=210)
/home/tom     192.168.1.130(ro)
 
#启用配置文件
[root@server ~]# exportfs -r
#因为客服户端要对/nfs/upload进行上传文件,因此要在服务端提权限,否则客户端创建文件权限不够
[root@server ~]# chmod o+w /nfs/upload
 
[root@server ~]# systemctl  restart nfs-server.service
 
 
客户端
 
#查看服务端的共享文件
[root@client ~]# showmount -e 192.168.1.130
Export list for 192.168.1.130:
/nfs/shared *
/nfs/upload 192.168.1.0/24
/home/tom   192.168.1.130
 
#创建目录
[root@client ~]# mkdir /mnt
[root@client mnt]# mkdir /mnt1
 
#挂载
[root@client ~]# mount 192.168.1.130:/nfs/shared  /mnt
[root@client ~]# ll /mnt
总计 0
-rw-r--r--. 1 root root 0  1月14日 16:54 a
-rw-r--r--. 1 root root 0  1月14日 16:54 b
-rw-r--r--. 1 root root 0  1月14日 16:54 c
-rw-r--r--. 1 root root 0  1月14日 16:54 d
 
[root@client mnt]# mount 192.168.1.130:/nfs/upload  /mnt1
[root@client mnt]# cd /mnt1
[root@client mnt1]# ll
总计 0
-rw-r--r--. 1 root root 0  1月14日 16:54 1
-rw-r--r--. 1 root root 0  1月14日 16:54 2
-rw-r--r--. 1 root root 0  1月14日 16:54 3
-rw-r--r--. 1 root root 0  1月14日 16:54 4
 
#上传文件,并且文件的用户和组映射为指定的UID,GID
[root@client mnt1]# touch 5
[root@client mnt1]# ll
总计 0
-rw-r--r--. 1 root root 0  1月14日 16:54 1
-rw-r--r--. 1 root root 0  1月14日 16:54 2
-rw-r--r--. 1 root root 0  1月14日 16:54 3
-rw-r--r--. 1 root root 0  1月14日 16:54 4
-rw-r--r--. 1  210  210 0  1月14日 17:12 5


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值