nginx\https\NFS配置

文章讲述了如何在OpenLab.com上搭建多站点,包括对学生信息、教学资料和缴费网站的权限管理,以及设置NFS服务器提供资源共享,并实现学生信息网站的访问权限控制和缴费网站的HTTPS加密。
摘要由CSDN通过智能技术生成

采用openEuler系统

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

#关闭防火墙和selinux
[root@server ~]# systemctl stop firewalld
[root@server ~]# setenforce 0
#下载并开启nginx
[root@server ~]# yum install  nginx  -y
[root@server ~]# systemctl start nginx
#配置文件
[root@server ~]# vim /etc/nginx/conf.d/test_name.conf
[root@server ~]# mkdir -pv /www/name/openlab
mkdir: 已创建目录 '/www'
mkdir: 已创建目录 '/www/name'
mkdir: 已创建目录 '/www/name/openlab'
[root@server ~]# echo 'welcome to openlab!!!' > /www/name/openlab/index.html
[root@server ~]# systemctl restart nginx
[root@server ~]# cat /etc/nginx/conf.d/test_name.conf
server{
	listen 192.168.221.131:80;
	root /www/name/openlab;
	server_name www.openlab.com;
	location / {
	}
}

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

#配置文件
[root@server ~]# vim /etc/nginx/conf.d/test_name.conf 
server{
        listen 192.168.221.131:80;
        root /www/name/openlab;
        server_name  www.openlab.com;
        location / {
                index index.html;
        }
}
server{
        listen 192.168.221.131:80;
        root /www/name/openlab/student;
        server_name www.openlab.com/student;
        location / {
                index index.html;
        }
server{
        listen 192.168.221.131:80;
        root /www/name/openlab/data;
        server_name www.openlab.com/data;
        location / {
                index index.html;
        }
}
server{
        listen 192.168.221.131:80;
        root /www/name/openlab/money;
        server_name www.openlab.com/money;
        location / {
                index index.html;
        }
}
#创建目录
[root@server ~]# mkdir -pv /www/name/openlab/{student,data,money}
mkdir: 已创建目录 '/www/name/openlab/student'
mkdir: 已创建目录 '/www/name/openlab/data'
mkdir: 已创建目录 '/www/name/openlab/money'
#写入内容
[root@server ~]# echo '这是学生信息网'  >   /www/name/openlab/student/index.html
[root@server ~]# echo '这是教学资料网'  >   /www/name/openlab/data/index.html
[root@server~]# echo '这是缴费网'  >   /www/name/openlab/money/index.html
#重启
[root@server ~]# systemctl restart nginx
#另一台虚拟机
[root@localhost ~]# vim /etc/hosts
192.168.221.131 www.openlab.com
192.168.221.131 www.openlab.com/student
192.168.221.131 www.openlab.com/data
192.168.221.131 www.openlab.com/money
#测试
[root@localhost ~]# curl http://www.openlab.com
welcome to openlab
[root@localhost ~]# curl http://www.openlab.com/student/
这是学生信息网
[root@localhost ~]# curl http://www.openlab.com/data/
这是教学资料网
[root@localhost ~]# curl http://www.openlab.com/money/
这是缴费网

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

#增加song和tian用户
[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
#配置文件
[root@server~]# vim /etc/nginx/conf.d/test_httpd.conf
server {
        listen 192.168.221.131:80;
        root  /www/name/openlab/student;
        server_name www.openlab.com/student;
        location / {
                index index.html;
                auth_basic on;
                auth_basic_user_file /etc/nginx/users;
        }
}
#测试
[root@localhost ~]# curl www.openlab.com/student/  song
Enter host password for user 'song':
这是学生信息网站
[root@localhost ~]# curl www.openlab.com/student/  tian
Enter host password for user 'tian':
这是学生信息网站

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

#修改https配置文件
[root@server ~]# vim /etc/nginx/conf.d/test_https.conf 
server {
        listen 192.168.221.131:443 ssl;
        root /www/name/openlab/money;
        server_name www.openlab.com;
        ssl_certificate /etc/pki/tls/certs/openlab.crt;
        ssl_certificate_key /etc/pki/tls/private/openlab.key;
        location / {
               index index.html
        }
}
[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

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

#客户端、服务端安装包并启动
[root@server ~]# yum install nfs-utils rpcbind -y
[root@server ~]# systemctl start nfs-server
1.开放/nfs/shared目录,供所有用户查询资料

server端

#创建目录
[root@server ~]# mkdir -p /nfs/shared 
#创建资料
[root@localhost ~]# ll /nfs/shared
总用量 0
[root@localhost ~]# touch /nfs/shared/资料{1..9}
[root@localhost ~]# ll /nfs/shared
总用量 0
-rw-r--r--. 1 root root 0  1月 15 17:46 资料1
-rw-r--r--. 1 root root 0  1月 15 17:46 资料2
-rw-r--r--. 1 root root 0  1月 15 17:46 资料3
-rw-r--r--. 1 root root 0  1月 15 17:46 资料4
-rw-r--r--. 1 root root 0  1月 15 17:46 资料5
-rw-r--r--. 1 root root 0  1月 15 17:46 资料6
-rw-r--r--. 1 root root 0  1月 15 17:46 资料7
-rw-r--r--. 1 root root 0  1月 15 17:46 资料8
-rw-r--r--. 1 root root 0  1月 15 17:46 资料9
[root@localhost ~]# 
#编写配置
[root@server ~]# vim /etc/exports 打开nfs的配置文件
/nfs/shared     *(ro) 
#使配置文件生效
[root@server ~]# exportfs -r
exportfs: /etc/exports [1]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/nfs/shared".
  Assuming default behaviour ('no_subtree_check').
  NOTE: this default has changed since nfs-utils version 1.0.x
#服务端查看共享目录
[root@server ~]# showmount -e
Export list for server:
/nfs/shared *
#客户端查看共享目录
[root@client ~]# showmount -e 192.168.221.131
Export list for 192.168.221.131:
/nfs/shared *
#客户端查找资料
[root@client ~]# mkdir /test
[root@client ~]# mount -o ro 192.168.221.131:/nfs /test
[root@client ~]# cd /test
[root@client test]# ll shared/
总用量 0
-rw-r--r--. 1 root root 0  1月 15 17:46 资料1
-rw-r--r--. 1 root root 0  1月 15 17:46 资料2
-rw-r--r--. 1 root root 0  1月 15 17:46 资料3
-rw-r--r--. 1 root root 0  1月 15 17:46 资料4
-rw-r--r--. 1 root root 0  1月 15 17:46 资料5
-rw-r--r--. 1 root root 0  1月 15 17:46 资料6
-rw-r--r--. 1 root root 0  1月 15 17:46 资料7
-rw-r--r--. 1 root root 0  1月 15 17:46 资料8
-rw-r--r--. 1 root root 0  1月 15 17:46 资料9
2.开放/nfs/upload目录,为192.168.221.0/24网段主机可以上传目录, 并将所有用户及所属的组映射为nfs-upload,其UID和GID均为210
[root@server ~]# mkdir /nfs/upload
[root@server ~]# touch /nfs/upload/资料qq{1..5}
[root@server ~]# ll /nfs/upload
总用量 0
-rw-r--r--. 1 root root 0  1月 15 18:09 资料qq1
-rw-r--r--. 1 root root 0  1月 15 18:09 资料qq2
-rw-r--r--. 1 root root 0  1月 15 18:09 资料qq3
-rw-r--r--. 1 root root 0  1月 15 18:09 资料qq4
-rw-r--r--. 1 root root 0  1月 15 18:09 资料qq5
[root@server ~]# vim /etc/exports
/nfs/upload 192.168.221.131/24(rw,all_squash,anonuid=210,anongid=210)
[root@server ~]# exportfs -r
exportfs: /etc/exports [1]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/nfs/shared".
  Assuming default behaviour ('no_subtree_check').
  NOTE: this default has changed since nfs-utils version 1.0.x
exportfs: /etc/exports [2]: Neither 'subtree_check' or 'no_subtree_check' specified for export "192.168.221.0/24:/nfs/upload".
  Assuming default behaviour ('no_subtree_check').
  NOTE: this default has changed since nfs-utils version 1.0.x
[root@server ~]# groupadd -g 210 nfs-upload
[root@server ~]# useradd -u 210 -g 210 nfs-upload
useradd warning: nfs-upload's uid 210 outside of the UID_MIN 1000 and UID_MAX 60000 range.
[root@server ~]# showmount -e
Export list for server:
/nfs/shared *
/nfs/upload 192.168.221.0/24
[root@server ~]# chmod o+w /nfs/upload
#客户端
[root@client ~]# showmount -e 192.168.221.131
Export list for 192.168.221.131:
/nfs/shared *
/nfs/upload 192.168.221.0/24
[root@client ~]# mount -o rw 192.168.221.131:/nfs /test
[root@client ~]# cd /test
[root@client test]# ll upload/
总用量 0
-rw-r--r--. 1 root root 0  1月 15 18:09 资料qq1
-rw-r--r--. 1 root root 0  1月 15 18:09 资料qq2
-rw-r--r--. 1 root root 0  1月 15 18:09 资料qq3
-rw-r--r--. 1 root root 0  1月 15 18:09 资料qq4
-rw-r--r--. 1 root root 0  1月 15 18:09 资料qq5
[root@client test]# touch 资料888
[root@client test]# ll upload/
总用量 0
-rw-r--r--. 1 root root 0  1月 15 18:09 资料qq1
-rw-r--r--. 1 root root 0  1月 15 18:09 资料qq2
-rw-r--r--. 1 root root 0  1月 15 18:09 资料qq3
-rw-r--r--. 1 root root 0  1月 15 18:09 资料qq4
-rw-r--r--. 1 root root 0  1月 15 18:09 资料qq5
-rw-r--r--. 1 210 210 0  1月 15 18:09 资料888
3.将/home/tom目录仅共享给192.168.221.131这台主机,并只有用户tom可以完全访问该目录
[root@server home]# mkdir /nfs/tom
[root@server home]# useradd tom
[root@server home]# chown tom:tom /nfs/tom
[root@server home]# vim /etc/exports
/nfs/tom        192.168.221.129/24(rw)
[root@server home]# exportfs -r
[root@server home]# showmount -e
Export list for server:
/nfs/shared *
/nfs/tom    192.168.221.129/24
/nfs/upload 192.168.221.0/24
  • 7
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值