综合练习:请给openlab搭建web网站
网站需求:
1.基于域名www.openlab.com可以访问网站内容为 welcome to openlab!!!
2.给该公司创建三个子界面分别显示学生信息,教学资料 和缴费网站,基于,www.openlab.com/data网站访问教学 资料 www.openlab.com/money网站访问缴费网站。
3.要求 (1)学生信息网站只有song和tian两人可以访问,其他 用户不能访问。 (2)访问缴费网站实现数据加密基于https访问。
mkdir -p /www/openlab #创建openlab文件夹
echo 'welcom to openlab' > /www/openlab/index.html #在网页中显示welcom to openlab
vim /etc/nginx/nginx.conf #进入nginx.conf修改数据
server {
listen 80;
server_name 192.168.159.130; #修改成创建的网址
root /www/openlab; #修改成创建的文件夹
}
修改配置结果
systemctl start nginx #重启服务
测试www.openlab.com网页结果
mkdir /www/openlab/data #创建文件夹data
echo 'data' > /www/openlab/data/index.html #在data网页中显示data
vim /etc/nginx/nginx.conf #进入nginx.conf继续修改数据,接着之前的继续向下编写
server {
listen 80;
server_name 192.168.159.130;
root /www/openlab;
location /data { # 增加如下子配置
alias /www/openlab/data;
index index.html index.htm;
}
增加子配置结果
systemctl start nginx #重启服务
测试www.openlab.com/data网页结果
mkdir /www/openlab/student #创建文件夹student
echo 'student' > /www/openlab/student/index.html #在student网页中显示student
useradd song #创建用户song和tian
passwd song
useradd tianpasswd tian
htpasswd -c /etc/nginx/passwd song # 密码123
htpasswd /etc/nginx/passwd tian
vim /etc/nginx.conf #进入nginx.conf继续修改数据,接着之前的继续向下编写
server {
listen 80;
server_name 192.168.159.130;
root /www/openlab;
location /data {
alias /www/openlab/data;
index index.html index.htm;
}
location /student { # 增加如下子配置
alias /www/openlab/student;
index index.html index.htm;
auth_basic "please input password";
auth_basic_user_file /etc/nginx/passwd;
}
增加子配置结果
systemctl start nginx #重启服务
测试www.openlab.com/student网页结果
mkdir /www/openlab/money #创建文件夹money
echo 'money' > /www/openlab/money/index.html #在money网页中显示money
openssl genrsa -aes128 2048 > /etc/nginx/money.key #在/etc/nginx目录下制作整数所用的私钥文件zy.key
[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]:chongqing # 省份
Locality Name (eg, city) []:chongqing # 城市
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 []:[email protected] # 邮箱
cd /etc/nginx #切换目录
cp money.key money.key.org #拷贝私钥密码
openssl rsa -in money.key.org -out money.key #重做
[root@server nginx]# openssl rsa -in money.key.org -out money.key
Enter pass phrase for money.key.org: # 输 入私钥密码
writing RSA key
vim /etc/nginx/nginx.conf #进入nginx.conf继续修改数据,接着之前的继续向下编写
server {
listen 80;
server_name www.openlab.com;
root /www/openlab;
location /data {
alias /www/openlab/data;
index index.html index.htm;
}
location /student {
alias /www/openlab/student;
index index.html index.htm;
auth_basic "please input password";
auth_basic_user_file /etc/nginx/passwd;
}}
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 restart nginx #重启服务
点击继续访问
测试www.openlab.com/money网页结果