网站需求:
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访问。
操作步骤:
1.基本配置
关闭防火墙:systemctl stop firewalld
关闭selinux:setenforce 0
安装nginx:yum install -y nginx
开启nginx服务:systemctl start nginx
查看nginx状态:systemctl status nginx
2.主页面配置
创建目录
mkdir -pv /test/www/openlab
页面文件
echo welcome to openlab > /test/www/openlan/index.html
编辑/etc/hosts文件
vim /etc/hosts
添加192.168.162.146 www.openlab.com
使用curl指令测试
curl www.openlab.com
3.配置data子页面
创建目录
mkdir -pv /test/www/openlab/data
echo welcome to data > /test/www/openlab/data/index.html
测试
curl www.openlab.com/data/
4.配置student子页面
要求:学生信息网站只有song和tian两人可以访问,其他用户不能访问
创建目录
mkdir -pv /test/www/openlab/student
echo welcome to student > /test/www/openlab/student/index.html
配置子配置文件
nginx程序目录:
[root@localhost nginx]# tree /etc/nginx
├── conf.d #子配置文件目录
├── default.d
├── fastcgi.conf
├── fastcgi.conf.default
├── fastcgi_params #用以翻译nginx的变量供php识别
├── fastcgi_params.default
├── koi-utf
├── koi-win
├── mime.types #用以配置文件的媒体文件类型
├── mime.types.default
├── nginx.conf #主配置文件
├── nginx.conf.default
├── scgi_params
├── scgi_params.default
├── uwsgi_params #用以配置nginx的变量供python识别
├── uwsgi_params.default
└── win-utf
#nginx服务配置文件nginx.conf的结构
文件配置:
vim /etc/nginx/conf.d/openlab.conf
/etc/nginx/users即为用户文件
安装htpasswd用以添加用户
yum install -y htpasswd
添加用户
htpasswd /etc/nginx/users song
添加密码即可创建成功
重启nginx服务
systemctl restart nginx
测试
curl www.openlab.com/student/---访问不成功
带用户测试:curl www.openlan.com/student -u song---访问成功
5.配置money文件
要求:访问缴费网站实现数据加密基于https访问
基本配置
mkdir -pv /test/www/money
echo welcome to money > /test/www/money/index.html
配置子配置文件
vim /etc/nginx/conf.d/openlab.conf
生成私钥文件key
密码设置:Enter PEM pass phrase:123456
再次输入:Verifying - Enter PEM pass phrase:123456
生成公钥文件crt
依次输入:国家,省,城市,组织,部门,常用名,邮箱地址。
重启nginx服务
systemctl restart nginx
测试
curl http://www.openlab.com/money/---访问失败
curl https://www.openlab.com/money/ ---成功
curl https://www.openlab.com/money/ -k跳过ssl证书验证