准备工作
虚拟机恢复快照
关闭防火墙、下载httpd,启动httpd服务、显示httpd服务是否开启
[root@server ~]# systemctl stop firewalld
[root@server ~]# yum install httpd -y
[root@server ~]# systemctl start httpd
[root@server ~]# systemctl enable httpd
[root@server ~]# systemctl status httpd
一、基于域名www.openlab.com可以访问网站内容为 welcome to openlab!!!
在Windows的 C:\Windows\System32\drivers\etc\hosts 文件进 行DNS映射
192.168.160.134 www.openlab.com # 添加
[root@server ~]# mkdir -p /www/openlab
[root@server ~]# echo 'welcom to openlab' > /www/openlab/index.html
[root@server ~]# vim /etc/nginx/nginx.conf
[root@server ~]# systemctl start nginx
[root@server ~]# cat /www/openlab/index.html
welcom to openlab
[root@server ~]# systemctl restart nginx
vim /etc/nginx/nginx.conf
在 # Windows端打开浏览器输入www.openlab.com测试
二、创建教学资料子网站www.openlab.com/data
[root@server ~]# mkdir /www/openlab/data
[root@server ~]# echo 'data' > /www/openlab/data/index.html
[root@server ~]# vim /etc/nginx/nginx.conf
[root@server ~]# systemctl restart nginx
vim /etc/nginx/nginx.conf
# Windows端打开浏览器输入www.openlab.com/data测试
三、创建学生信息子网站www.openlab.com/student
[root@server ~]# mkdir /www/openlab/student
[root@server ~]# echo 'student' > /www/openlab/student/index.html
[root@server ~]# useradd song
[root@server ~]# passwd song #密码是123456
[root@server ~]# useradd tian
[root@server ~]# passwd tian #密码是123
[root@server ~]# htpasswd -c /etc/nginx/passwd song
New password:
Re-type new password:
Adding password for user song
[root@server ~]# htpasswd /etc/nginx/passwd tian
New password:
Re-type new password:
Adding password for user tian
[root@server ~]# vim /etc/nginx/nginx.conf
[root@server ~]# systemctl restart nginx
vim /etc/nginx/nginx.conf
Windows端打开浏览器输入 www.openlab.com/student测试
四、创建缴费子网站www.openlab.com/money
[root@server ~]# mkdir /www/openlab/money
[root@server ~]# echo 'money' > /www/openlab/money/index.html
[root@server ~]# openssl genrsa -aes128 2048 > /etc/nginx/money.key
Generating RSA private key, 2048 bit long modulus (2 primes)
...............+++++
.................+++++
e is 65537 (0x010001)
Enter pass phrase: #密码123456
Verifying - Enter pass phrase:
制作证书
[root@server ~]# openssl req -utf8 -new -key /etc/nginx/money.key -x509 -days 365 -out /etc/nginx/money.crt
Enter pass phrase for /etc/nginx/money.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]:ningxia
Locality Name (eg, city) []:yinchuan
Organization Name (eg, company) [Internet Widgits Pty Ltd]:openlab
Organizational Unit Name (eg, section) []:RHCE
Common Name (e.g. server FQDN or YOUR name) []:server
Email Address []:andy@qq.com
[root@server ~]# cd /etc/nginx
[root@server nginx]# cp money.key money.key.org
[root@server nginx]# openssl rsa -in money.key.org -out money.key
Enter pass phrase for money.key.org:
writing RSA key
[root@server nginx]# vim /etc/nginx/nginx.conf
[root@server nginx]# systemctl restart nginx