Web服务器实验案例

目录

关闭或放行防火墙和selinux

[1 搭建静态网站](#1 搭建静态网站)

[2 建立两个基于ip地址访问的网站](#2 建立两个基于ip地址访问的网站)

思路:

简单配置

编写httpd额外文件

[3 建立两个基于不同端口访问的网站](#3 建立两个基于不同端口访问的网站)

思路

创建文件(与之前一致)

额外文件配置

[4 基于虚拟目录和用户控制的web网站](#4 基于虚拟目录和用户控制的web网站)

思路

设置用户密码

创建目录及页面

编写配置文件

额外配置文件(必须制定目录及虚拟主机)

关闭或放行防火墙和selinux

1****搭建静态网站

复制代码
[root@localhost ~]# echo "this is static" >> /var/www/html/index.html

2建立两个基于ip****地址访问的网站

要求:访问 ip 地址为 100 时,访问的是 100 网页
访问 ip 地址为 200 时,访问 200 网页

思路:

创建 2 个 ip
创建 2 个 ip 对应的目录
使用 httpd 的额外文件来编写配置文件
创建虚拟主机

简单配置

复制代码
nmcli connection modify ens33 +ipv4.addresses 192.168.27.100/24
nmcli connection modify ens33 +ipv4.addresses 192.168.27.200/24
nmcli connection up ens33
mkdir -pv /WWW/ip/100
mkdir -pv /WWW/ip/200
echo "this is 100" > /WWW/ip/100/index.html
echo "this is 200" > /WWW/ip/200/index.html
配置httpd虚拟主机
虚拟主机样例文件是/usr/share/doc/httpd-2.4.6/httpd-vhosts.con
[root@localhost ~]# find / -name "*vhosts.conf"
/usr/share/doc/httpd-2.4.6/httpd-vhosts.conf

编写httpd额外文件

复制代码
[root@localhost ~]# more /etc/httpd/conf.d/vhosts.conf
<VirtualHost 192.168.27.100:80>
DocumentRoot /WWW/ip/100
ServerName 192.168.27.100
</VirtualHost>
<VirtualHost 192.168.27.200:80>
DocumentRoot /WWW/ip/200
ServerName 192.168.27.200
</VirtualHost>
给目录给予访问权限
<Directory "/WWW/ip">
AllowOverride None
Require all granted
</Directory>

3****建立两个基于不同端口访问的网站

思路

ip 已经创建
创建两个不同端口的目录
修改之前的额外文件

创建文件(与之前一致)

额外文件配置

复制代码
listen 81
listen 82
<VirtualHost 192.168.27.100:81>
DocumentRoot /WWW/port/81
ServerName 192.168.27.100
</VirtualHost>
<VirtualHost 192.168.27.100:82>
DocumentRoot /WWW/port/82
ServerName 192.168.27.100
</VirtualHost>
<Directory "/WWW/port">
AllowOverride None
Require all granted
</Directory>

4基于虚拟目录和用户控制的web****网站

思路

设置用户和密码
创建页面文件目录
编写配置文件

设置用户密码

复制代码
htpasswd -c /etc/httpd/mymima xiaoming
htpasswd -c /etc/httpd/mymima xiaohong

创建目录及页面

复制代码
mkdir /usr/local/mysecret
echo "this is mysecret" > /usr/local/mysecret/index.html

编写配置文件

额外配置文件(必须制定目录及虚拟主机)

复制代码
[root@localhost ~]# more /etc/httpd/conf.d/vhosts2.conf
<Directory "/usr/local">
AuthType Basic
AuthName "please login"
AuthUserFile /etc/httpd/mymima
Require user xiaohong
</Directory>
<VirtualHost 192.168.27.100:80>
DocumentRoot "/usr/local/mysecret"
ServerName 192.168.27.100
</VirtualHost>
相关推荐
Csvn1 小时前
Vue 3 defineModel 翻车实录:多个 v-model 绑定到底怎么写?
前端·vue.js
甲维斯1 小时前
坦克大战测试全翻车了!豆包,DeepSeek,Qwen,GPT,Claude
前端·人工智能·游戏开发
乘风gg2 小时前
还在养虾吗?虾王已诞生:微信龙虾 ClawBot
前端·ai编程·claude
小小小小宇2 小时前
LLM 长期记忆构建
前端
lichenyang4532 小时前
从 Express 老项目到 NestJS + Docker:一次车辆管理系统的渐进式重构
前端
Momo__4 小时前
VueUse createReusableTemplate —— 单文件组件内的模板复用神器
前端·vue.js
程序员小富4 小时前
我开源了一个开发者专属的智能 JSON 工具,得到了媳妇高度认可
前端·vue.js·后端
小小小小宇4 小时前
程序员如何给 LLM 装工具以及看懂推理过程
前端
写代码的皮筏艇4 小时前
React中的forwardRef
前端·react.js·面试
槑有老呆4 小时前
花三个月工资请了个 AI 程序员,结果它连青岛啤酒股价都查不了
前端