一、作业目标
给openlab搭建web网站,要求:
1、基于域名www.openlab可以访问网站内容为 welcome to openlab!!! 。
2、给该公司创建三个子界面分别显示学生信息(www.openlab.com/student),教学资料(www.openlab.com/data)和缴费网站(www.openlab.com/noney)。
3、学生信息网站只有song和tian两人可以访问,其他用户不能访问;
访问缴费网站实现数据解密基于https访问。
二、目标1
输入yum install nginx httpd-tools -y 安装所需软件
在C:\Windows\System32\drivers\etc\hosts 文件中添加 192.168.86.129 www.openlab.com
输入mkdir -p /www/openlab
输入echo ‘"elcome to openlab!!! "> /www/openlab/index.html
输入vim /etc/nginx/nginx.conf
将第41行改为server_name www.openlab.com;
第42行改为server_name www.openlab.com;
输入systemctl start nginx 重启nginx服务
测试 在浏览器中输入www.openlab.com 发现成功打开网站并输出
三、目标2
1、开始创建教学资料页面(www.openlab.com/data)
输入mkdir /www/openlab/data
输入echo "data" > /www/openlab/data/index.html
输入 vim /etc/nginx/nginx.conf
在第43行插入
location /data {
alias /www/openlab/data;
index index.html index.htm;
}
输入systemctl start nginx 重启nginx服务
测试 在浏览器中输入www.openlab.com/data 发现成功打开网站并输出
2、开始创建学生信息页面(www.openlab.com/student)
输入mkdir /www/openlab/student
输入 echo "student" > /www/openlab/student/index.html
输入useradd song 开始创建账户 song
输入passwd song 并输入对应密码
输入useradd tian 开始创建账户tian
输入passwd tian 并输入对应密码
输入htpasswd -c /etc/nginx/passwd song
输入htpasswd -c /etc/nginx/passwd tian 向密码文件(/etc/nginx/passwd) 中添加新用户 song和tian。
输入vim /etc/nginx/nginx.conf
在第48行插入location /student {
alias /www/openlab/student;
index index.html index.htm;
auth_basic "Please input password";
auth_basic_user_file /etc/nginx/passwd;
}
输入systemctl restart nginx
测试 在浏览器中输入www.openlab.com/student 发现需要登录信息,在成功登录后显示网页
3、开始创建缴费网站页面(www.openlab.com/noney)
输入mkdir /www/openlab/money
输入echo "money" > /www/openlab/money/index.html
输入openssl genrsa -aes128 2048 > /etc/nginx/money.key 创建加密私钥并设置密码
openssl req -utf8 -new -key /etc/nginx/money.key -x509 -days 365 -out /etc/nginx/money.crt
制作证书并输入相关内容
输入vim /etc/nginx/nginx.conf
插入
server {
listen 443 ssl http2;
server_name www.openlab.com;
location /money {
alias /www/openlab/money;
index index.html index.htm;
}
ssl_certificate "/etc/nginx/money.crt";
ssl_certificate_key "/etc/nginx/money.key";
}
输入systemctl start nginx 重启nginx服务
测试 在浏览器中输入www.openlab.com/money 发现成功打开网站并输出