RHCSA作业3
网站需求:
1.基于域名www.openlab.com可以访问网站内容为 welcome to openlab!!!
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# yum install nginx -y[root@localhost ~]# vim /etc/nginx/nginx.confserver{listen 80;root /www/openlab;server_name www.openlab.com;location / {}
}[root@localhost ~]# mkdir /www/openlab/ -p
[root@localhost ~]# echo welcome to openlab!!! > /www/openlab/index.html
配置域名解析
[root@localhost ~]# cat /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.188.129 www.openlab.com //写入当前主机IP和域名配置[root@localhost ~]# curl www.openlab.com //检验实验结果
welcome to openlab!!!2.给该公司创建三个子界面分别显示学生信息,教学资料和缴费网站,基于www.openlab.com/student 网站访问学生信息,www.openlab.com/data网站访问教学资料,www.openlab.com/money网站访问缴费网站。
#更改配置文件[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 {}}#创建三个目录并在对应的index.html中写入[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.html3.要求
(1)访问该网站http请求都通过https响应。
(2)学生信息网站只有song和tian两人可以访问,其他用户不能访问。
#创建可访问的用户和密码文件[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 ~]# 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 [root@localhost ~]# systemctl restart nginx
