admin管理员组

文章数量:1794759

Linux下搭建Web网站

Linux下搭建Web网站

网站需求: 1.基于域名www.openlab可以访问网站内容为 welcome to openlab!!! 2.给该公司创建三个网站目录分别显示学生信,教学资料和缴费网站,基于 www.openlab/student 网站访问学生信,www.openlab/data 网站访问教学资料 ,www.openlab/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+域名即可

本文标签: 网站Linuxweb