RHCE第三次作业
网站需求:
1.基于域名www.openlab.com可以访问网站内容为 welcome to openlab!!!
2.给该公司创建三个子界面分别显示学生信息,教学资料和缴费网站,基于www.openlab.com/student 网站访问学生信息,www.openlab.com/data网站访问教学资料
www.openlab.com/money网站访问缴费网站。
3.要求 (1)访问该网站http请求都通过https响应。
(2)学生信息网站只有song和tian两人可以访问,其他用户不能访问
准备工作
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0还有安装nainx
IP与域名映射关系
C:\Window\System32\drivers\etc的hosts文件 在最后一行添加虚拟IP与域名

1.基于域名www.openlab.com可以访问网站内容为 welcome to openlab!!!
[root@localhost ~]# vim /etc/nginx//nginx.confserver {listen 80;listen [::]:80;server_name www.openlab.com;root /www/openlab;# Load configuration files for the default server block.include /etc/nginx/default.d/*.conf;error_page 404 /404.html;[root@localhost ~]# mkdir /www/openlab/ -p
[root@localhost ~]# echo "welconme to openlabmkdir " > /www/openlab/index.html
[root@localhost ~]# systemctl restart nginx
测试

2.给该公司创建三个子界面分别显示学生信息,教学资料和缴费网站,基于www.openlab.com/student 网站访问学生信息,www.openlab.com/data网站访问教学资料
www.openlab.com/money网站访问缴费网站。
[root@localhost ~]# mkdir /www/openlab/student
[root@localhost ~]# mkdir /www/openlab/data
[root@localhost ~]# mkdir /www/openlab/money
[root@localhost ~]# echo "this is student " > /www/openlab/student/index.html
[root@localhost ~]# echo "this is data " > /www/openlab/data/index.html
[root@localhost ~]# echo "this is money " > /www/openlab/money/index.html[root@localhost ~]# vim /etc/nginx/nginx.conf
server {listen 80;listen [::]:80;server_name www.openlab.com;root /www/openlab;location /data {alias /www/openlab/data;index index.html;} location /money {alias /www/openlab/money;index index.html;}location /student {alias /www/openlab/student;index index.html;auth_basic "please input password";auth_basic_user_file /www/openlab/student/passwd;}# Load configuration files for the default server block.include /etc/nginx/default.d/*.conf;error_page 404 /404.html;location = /404.html {}error_page 500 502 503 504 /50x.html;location = /50x.html {}}
(2)学生信息网站只有song和tian两人可以访问,其他用户不能访问
[root@localhost ~]# useradd song
[root@localhost ~]# passwd song
更改用户 song 的密码 。
新的密码:
无效的密码: 密码少于 8 个字符
重新输入新的密码:
passwd:所有的身份验证令牌已经成功更新。
[root@localhost ~]# useradd tian
[root@localhost ~]# passwd tian
更改用户 tian 的密码 。
新的密码:
无效的密码: 密码少于 8 个字符
重新输入新的密码:
passwd:所有的身份验证令牌已经成功更新。[root@localhost ~]# htpasswd -c /www/openlab/student/passwd song
New password:
Re-type new password:
Adding password for user song
[root@localhost ~]# htpasswd /www/openlab/student/passwd tian
New password:
Re-type new password:
Adding password for user tian
[root@localhost ~]# cat /www/openlab/student/passwd
song:$apr1$wkDsFwlo$d8jJ0szplOeSWUeJKpRnw1
tian:$apr1$hOVeARN/$Kx8C5wtNzhxbKdsHLfdN81

1)访问该网站http请求都通过https响应。
修改[root@localhost ~]# vim /etc/nginx/nginx.conf
server {listen 443 ssl http2; #改listen [::]:443 ssl http2;#改server_name www.openlab.com;root /www/openlab;location /data {alias /www/openlab/data;index index.html;}location /money {alias /www/openlab/money;index index.html;}location /student {alias /www/openlab/student;index index.html;auth_basic "please input password";auth_basic_user_file /www/openlab/student/passwd;}ssl_certificate "/www/openlab/openlab.crt"; #以下添加ssl_certificate_key "/www/openlab/openlab.key";ssl_session_cache shared:SSL:1m;ssl_session_timeout 10m;ssl_ciphers PROFILE=SYSTEM;ssl_prefer_server_ciphers on;[root@localhost ~]# openssl genrsa 2048 > /www/openlab/openlab.key
[root@localhost ~]# openssl req -utf8 -new -key /www/openlab/openlab.key -x509 -days 365 -out /www/openlab/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) [XX]:86
State or Province Name (full name) []:jiangsu
Locality Name (eg, city) [Default City]:nanjing
Organization Name (eg, company) [Default Company Ltd]:openlab
Organizational Unit Name (eg, section) []:openlab
Common Name (eg, your name or your server's hostname) []:server
Email Address []:123@123
[root@localhost ~]# systemctl restart nginx
测试
