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访问。

准备

1.需要两台Linux虚拟机,一台为服务端server,另一台为客户端client

server IPV4:192.168.110.136/24 client IPV4:192.168.110.134/24

2.服务端需要关闭防火墙和Linux的安全服务seLinux

root@server \~\]# systemctl stop firewalld \[root@server \~\]# setenforce 0 \[root@server \~\]# getenforce Permissive 3.安装httpd,mol_ssl \[root@server \~\]# yum install -y httpd mod_ssl

配置

1.客户端通过IP地址可以正常访问服务端内容

root@server \~\]# mkdir -v /openlab/ #创建目录 已创建目录 '/openlab/' \[root@server \~\]# echo "welcome to openlab!!!" \> /openlab/index.html #写入内容 \[root@server \~\]# vim /etc/httpd/conf.d/openlab.conf #打开httpd的额外参数配置文件 \ Options Indexes FollowSymLinks AllowOverride None Require all granted \ \ ServerAdmin [email protected] DocumentRoot "/openlab/" ServerName www.openlab.com \ \[root@server \~\]# httpd -t #语法检测 Syntax OK \[root@server \~\]# systemctl restart httpd #重启服务 客户端访问 \[root@client \~\]# curl 192.168.110.136 welcome to openlab!!! ![](https://file.jishuzhan.net/article/1722566353849683970/8212dc5f4dd4f7620509575a06117311.webp) ![](https://file.jishuzhan.net/article/1722566353849683970/0a57901c6e3241e81b80b454c1815d86.webp)

2.搭建学生信息,教学资料,缴费网站页面

root@server \~\]# mkdir /openlab/{student,data,money} -v mkdir: 已创建目录 '/openlab/student' mkdir: 已创建目录 '/openlab/data' mkdir: 已创建目录 '/openlab/money' \[root@server \~\]# echo "学生信息" \> /openlab/student/index.html #写入内容 \[root@server \~\]# echo "教育网站" \> /openlab/data/index.html #写入内容 \[root@server \~\]# echo "缴费网站" \> /openlab/money/index.html #写入内容 首先配置student页面只有song和tian用户访问 \[root@server \~\]# htpasswd -c /etc/httpd/conf.d/httpd song #创建sond的身份验证文件 New password: Re-type new password: Adding password for user song \[root@server \~\]# htpasswd /etc/httpd/conf.d/httpd tian #添加tain的身份验证文件 New password: Re-type new password: Adding password for user tian \[root@server \~\]# cat /etc/httpd/conf.d/httpd song:$apr1$XWPO6i0/$hNsM5W/Gx3ukFsPokAEEH. tian:$apr1$SSblX1SO$YGyWDIuzZmCuLfhBnqn6m1 \[root@server \~\]# vim /etc/httpd/conf.d/openlab.conf #在额外参数配置文件添加内容 \ ServerAdmin [email protected] DocumentRoot "/openlab/student" ServerName www.openlab.com \ \ Options Indexes FollowSymLinks AllowOverride None AuthType Basic AuthName "Restricted Files" AuthUserFile "/etc/httpd/conf.d/httpd " #身份验证文件的路径 Require user song tian #允许访问的用户 \ \[root@server \~\]# httpd -t #语法检测 Syntax OK \[root@server \~\]# systemctl restart httpd #重启服务 客户端访问 \[root@client \~\]# curl 192.168.110.136/student/ -u song Enter host password for user 'song': 学生信息 \[root@client \~\]# curl 192.168.110.136/student/ -u tian Enter host password for user 'tian': 学生信息 ![](https://file.jishuzhan.net/article/1722566353849683970/1befe30d14a266fadc29a4236f6c903f.webp) 其他用户访问 ![](https://file.jishuzhan.net/article/1722566353849683970/440ed50a8eb03f5c9da8f8bdf91b9eb1.webp) ![](https://file.jishuzhan.net/article/1722566353849683970/b30d0603cb1dc73a63312f89cc1f4275.webp) ![](https://file.jishuzhan.net/article/1722566353849683970/a3665429e6e72444b0885400b8782316.webp) 配置教学资料网站所有用户都可访问 \[root@server \~\]# vim /etc/httpd/conf.d/openlab.conf #打开配置文件添加内容 \ Options Indexes FollowSymLinks AllowOverride None Require all granted \ \ ServerAdmin [email protected] DocumentRoot "/openlab/data/" ServerName www.openlab.com \ \[root@server \~\]# httpd -t Syntax OK \[root@server \~\]# systemctl restart httpd 客户端访问 \[root@client \~\]# curl 192.168.110.136/data/ 教育网站 ![](https://file.jishuzhan.net/article/1722566353849683970/13356cffd559ae724bd5edd85b1e31da.webp) ![](https://file.jishuzhan.net/article/1722566353849683970/ca634d77297a6541735a58e2630ad4f2.webp) 配置缴费网站实现数据加密基于https访问 \[root@server \~\]# cd /etc/pki/tls/certs/ #存放着一些证书文件 \[root@server certs\]# openssl genrsa 2048 \>\> openlab.key #生成私钥文件 \[root@server certs\]# openssl req -utf8 -new -key openlab.key -x509 -days 100 -out openlab.crt #生成证书 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) \[XX\]:SN #国家 State or Province Name (full name) \[\]:CN #省份 Locality Name (eg, city) \[Default City\]:XI'AN #城市 Organization Name (eg, company) \[Default Company Ltd\]:OPENLAB #企业 Organizational Unit Name (eg, section) \[\]:RHCE #部门 Common Name (eg, your name or your server's hostname) \[\]:www.openlab.com 域名 Email Address \[\]:[email protected] #邮件 \[root@server \~\]# vim /etc/httpd/conf.d/openlab.conf \ DocumentRoot "/openlab/money/" ServerName www.openlab.com SSLEngine on SSLCertificateFile "/etc/pki/tls/certs/openlab.crt" SSLCertificateKeyFile "/etc/pki/tls/certs/openlab.key" \ \ Options Indexes FollowSymLinks AllowOverride None Require all granted \ \[root@server \~\]# httpd -t Syntax OK \[root@server \~\]# systemctl restart httpd 客户端访问 \[root@client \~\]# curl https://192.168.110.136 -k #-k为忽略证书访问 缴费网站 \[root@client \~\]# curl 192.168.110.136/money/ -k 缴费网站 ![](https://file.jishuzhan.net/article/1722566353849683970/293e17e1aef64113bedf191e0957ad98.webp) ![](https://file.jishuzhan.net/article/1722566353849683970/323ff3f0a3f98e2890c269d7b0b1ff3e.webp)![](https://file.jishuzhan.net/article/1722566353849683970/123feaee1c488c6f6ab2855c562fb522.webp) /etc/httpd/conf.d/openlab.conf配置文件最终内容 ![](https://file.jishuzhan.net/article/1722566353849683970/cd786d4c99e93a9e415fd829ec0fd319.webp)

3.客户端通过域名可以正常访问服务端内容

在没有DNS域名解析服务器的情况下可以使用本机hosts文件,hosts文件其作用就是将一些常用的网址域名与其对应的IP地址建立一个关联"数据库"

在Linux下hosts文件地址为/etc/host

root@client \~\]# vim /etc/hosts #写入内容 192.168.110.136 www.openlab.com \[root@client \~\]# curl www.openlab.com welcome to openlab!!! \[root@client \~\]# curl www.openlab.com/student/ -u song Enter host password for user 'song': 学生信息 \[root@client \~\]# curl www.openlab.com/student/ -u tian Enter host password for user 'tian': 学生信息 \[root@client \~\]# curl www.openlab.com/data/ 教育网站 \[root@client \~\]# curl https://www.openlab.com -k 缴费网站 \[root@client \~\]# curl www.openlab.com/money/ -k 缴费网站 ![](https://file.jishuzhan.net/article/1722566353849683970/a9e3efbd885c556ce263271c7d741517.webp) 在Windows客户端下hosts文件路径为C:\\Windows\\System32\\drivers\\etc\\hosts ![](https://file.jishuzhan.net/article/1722566353849683970/fc57035fde7ef1a760fc7dfbfc45fdf7.webp) 添加内容,浏览器访问即可

相关推荐
段ヤシ.13 分钟前
银河麒麟(内核CentOS8)安装rbenv、ruby2.6.5和rails5.2.6
linux·centos·银河麒麟·rbenv·ruby2.6.5·rails 5.2.6
IT瘾君1 小时前
JavaWeb:Html&Css
前端·html
264玫瑰资源库2 小时前
问道数码兽 怀旧剧情回合手游源码搭建教程(反查重优化版)
java·开发语言·前端·游戏
喝拿铁写前端2 小时前
从圣经Babel到现代编译器:没开玩笑,普通程序员也能写出自己的编译器!
前端·架构·前端框架
HED2 小时前
VUE项目发版后用户访问的仍然是旧页面?原因和解决方案都在这啦!
前端·vue.js
深夜情感老师2 小时前
centos离线安装ssh
linux·centos·ssh
我的作业错错错2 小时前
搭建私人网站
服务器·阿里云·私人网站
拉不动的猪2 小时前
前端自做埋点,我们应该要注意的几个问题
前端·javascript·面试
王景程2 小时前
如何测试短信接口
java·服务器·前端
安冬的码畜日常3 小时前
【AI 加持下的 Python 编程实战 2_10】DIY 拓展:从扫雷小游戏开发再探问题分解与 AI 代码调试能力(中)
开发语言·前端·人工智能·ai·扫雷游戏·ai辅助编程·辅助编程