Linux下搭建Web网站

网站需求:
1.基于域名www.openlab.com可以访问网站内容为 welcome to openlab!!!
2.给该公司创建三个网站目录分别显示学生信息,教学资料和缴费网站,基于 www.openlab.com/student 网站访问学生信息,www.openlab.com/data 网站访问教学资料 ,www.openlab.com/money 网站访问缴费网站。
3.要求:
(1)学生信息网站只有song和tian两人可以访问,其他网站所有用户用能访问。
(2)访问缴费网站实现数据加密基于https访问

搭建:

一、
①在yum配置好的情况下首先安装HTTP和HTTPS包

[root@localhost ~]# yum install httpd -y				安装HTTP包
  • 1

在这里插入图片描述

[root@localhost ~]# yum install mod_ssl -y			安装HTTPS包
  • 1

在这里插入图片描述
②进入配置文件进行编辑

[root@localhost ~]# vim /etc/httpd/conf.d/vhost.conf			进入编辑文件
  • 1

在这里插入图片描述

[root@localhost ~]# systemctl restart httpd                 重启HTTP服务
[root@localhost ~]# systemctl stop firewalld.service 		关闭防火墙
[root@localhost ~]# setenforce 0							关闭selinux
[root@localhost ~]# mkdir /www/openlab -pv 					创建www和openlab目录
[root@localhost ~]# vim /www/openlab/index.html 			编写静态网页内容
  • 1
  • 2
  • 3
  • 4
  • 5

在这里插入图片描述

[root@localhost ~]# vim /etc/hosts							更改hosts文件,能在浏览器中通过域名访问
  • 1

在这里插入图片描述
测试:
在这里插入图片描述
输入域名后页面就能显示自己写的东西啦!

二、

[root@localhost ~]# vim /etc/httpd/conf.d/vhost.conf			进入编辑文件
  • 1

在这里插入图片描述

[root@localhost ~]# htpasswd -c /etc/httpd/studentpwd song		添加用户song并设置密码,第一次添加需要+-c选项
 New password: 
Re-type new password: 
Adding password for user song			
[root@localhost ~]# htpasswd /etc/httpd/studentpwd tian			添加用户tian并设置密码
 New password: 
Re-type new password: 
Adding password for user tian

[root@localhost ~]# mkdir /usr/local/money						创建money目录
[root@localhost ~]# mkdir /www/openlab/student					创建student目录
[root@localhost ~]# mkdir /www/openlab/data						创建data目录

[root@localhost ~]# cd /etc/pki/tls/certs/						切换到certs目录
[root@localhost certs]# make openlab.crt						创建证书
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

在这里插入图片描述
然后进入vhost.conf文件更改证书路径
在这里插入图片描述
重启HTTP服务
分别进行测试:
在这里插入图片描述
在这里插入图片描述需要输入用户和密码才能登陆
在这里插入图片描述

在这里插入图片描述基于HTTPS登陆,由于证书不受信任,所有出现警告,可添加为例外登陆
在这里插入图片描述

到此,完成静态Web网站的搭建,动态网站的搭建方法类似,需要使用python等脚本语言进行编写并和数据库进行数据互联,就可以达到预期的效果!!!

注:本次实验使用的redhat7.0版本系统并基于VMware Workstation 模拟器进行操作
若想在Windows系统下用浏览器登陆需修改Windows下的hosts文件

在这里插入图片描述
选择用记事本打开,写入指定的IP+域名即可
在这里插入图片描述
在这里插入图片描述

  • 1
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值