要求
1.基于域名[www.openlab.com](http://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网站访问缴费网站)。
3.要求 (1)学生信息网站只有song和tian两人可以访问,其他用户不能访问。
(2)访问缴费网站实现数据加密基于https访问。
架设一台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可以完全访问该目录
准备工作
(1)关闭防火墙,便于访问Linux虚拟机上服务
(2)设置selinux为permissive模式
[root@localhost ~]# setenforce 0
[root@localhost ~]# getenforce
Permissive
(3)安装相应的nginx包和httpd包
[root@localhost ~]# yum install nginx -y
[root@localhost ~]# yum install httpd -y
[root@localhost ~]# yum install httpd-tools
1.基于域名[www.openlab.com](http://www.openlab.com)可以访问网站内容为 welcome to openlab!!!
1.使用vim编辑/etc/nginx/conf.d/openlab.conf文件
2.创建目录并将要输出内容写入里面
[root@localhost ~]# mkdir /www/openlab -pv
mkdir: 已创建目录 '/www'
mkdir: 已创建目录 '/www/openlab'
[root@localhost ~]# echo www.openlab.com\!\!\! > /www/openlab/index.html
[root@localhost ~]# cat /www/openlab/index.html
www.openlab.com!!!
3.重启nginx服务端
[root@localhost ~]# systemctl restart nginx
使用客户端进行测试
[root@localhost ~]# vim /etc/hosts
# Loopback entries; do not change.
# For historical reasons, localhost precedes localhost.localdomain:
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
# See hosts(5) for proper format and other examples:
# 192.168.1.10 foo.mydomain.org foo
# 192.168.1.13 bar.mydomain.org bar
192.168.44.135 www.openlab.com
~
[root@localhost ~]# curl www.openlab.com
www.openlab.com!!!
2.给该公司创建三个子界面分别显示学生信息,教学资料和缴费网站,基于[www.openlab.com/student](http://www.openlab.com/student) 网站访问学生信息,[www.openlab.com/data](http://www.openlab.com/data)网站访问教学资料,网站访问缴费网站(http://www.openlab.com/money网站访问缴费网站)。
3.要求 (1)学生信息网站只有song和tian两人可以访问,其他用户不能访问。
(2)访问缴费网站实现数据加密基于https访问。
1.使用 vim 编辑/etc/nginx/conf.d/openlab.conf
[root@localhost ~]# vim /etc/nginx/conf.d/openlab.conf
server {
listen 192.168.44.135:80;
server_name www.openlab.com;
root /www/openlab;
location /student{
index index.html;
alias /www/openlab/student;
auth_basic on;
auth_basic_user_file /etc/nginx/users;
}
}
2.创建三个子目录并写入内容
[root@localhost ~]# mkdir /www/openlab/{data,money,student} -pv
mkdir: 已创建目录 '/www/openlab/data'
mkdir: 已创建目录 '/www/openlab/money'
mkdir: 已创建目录 '/www/openlab/student'
[root@localhost ~]# echo 教学资料 > /www/openlab/data/index.html
[root@localhost ~]# echo 缴费网站 > /www/openlab/money/index.html
[root@localhost ~]# echo 学生信息 > /www/openlab/student/index.html
3.重启nginx服务端
[root@localhost ~]# systemctl restart nginx
进行测试
[root@localhost ~]# curl www.openlab.com/data/
教学资料
[root@localhost ~]# curl www.openlab.com/money/
缴费网站
[root@localhost ~]# curl www.openlab.com/student/
学生信息
4.添加用户信息
[root@localhost ~]# htpasswd -c /etc/nginx/usrs song
New password:
Re-type new password:
Adding password for user song
[root@localhost ~]# htpasswd /etc/nginx/usrs tian
New password:
Re-type new password:
Adding password for user tian
(1)学生信息网站只有song和tian两人可以访问,其他用户不能访问。
测试
[root@localhost ~]# curl www.openlab.com/student/ -u song:123456
学生信息
[root@localhost ~]# curl www.openlab.com/student/ -u tian:123456
学生信息
(2)访问缴费网站实现数据加密基于https访问。
1.修改配置文件
server {
listen 192.168.44.135:80;
server_name www.openlab.com;
root /www/openlab;
2.16.44.1location /student{
index index.html;
alias /www/openlab/student;
auth_basic on;
auth_basic_user_file /etc/nginx/users;
server {
listen 192.168.44.135: ssl ;
server_name www.openlab.com;
root /www;
ssl_certificate "/etc/pki/tls/certs/openlab.crt";
ssl_certificate_key "/etc/pki/tls/private/openlab.key";
location / {
index index.html;
}
进行加密
[root@localhost ~]# openssl genrsa -aes128 2048 > /etc/pki/tls/private/openlab.key
Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:
[root@localhost ~]# openssl req -utf8 -new -key /etc/pki/tls/private/openlab.key -x509 -days 365 -out /etc/pki/tls/certs/openlab.crt
Enter pass phrase for /etc/pki/tls/private/openlab.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]:11
Locality Name (eg, city) []:21
Organization Name (eg, company) [Internet Widgits Pty Ltd]:1
Organizational Unit Name (eg, section) []:4
Common Name (e.g. server FQDN or YOUR name) []:5
Email Address []:5
测试
[root@localhost ~]# curl https:/www.openlab.com/money/ -k
缴费网站