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>
相关推荐
IT_陈寒4 分钟前
Vue 3.4 性能优化揭秘:这5个Composition API技巧让我的应用提速40%
前端·人工智能·后端
infiniteWei5 分钟前
【VIM 入门到精通】快速查找与替换:定位和修改文本的利器
linux·编辑器·vim
行走的陀螺仪6 分钟前
实时通信底层原理深度剖析:短轮询、长轮询与WebSocket的本质差异
前端·网络·websocket·网络协议
大猩猩X7 分钟前
vue vxe-gantt 甘特图实现产品进度列表,自定义任务条样式和提示信息
前端·javascript·甘特图·vxe-ui·vxe-gantt
一字白首9 分钟前
Vue 进阶,生命周期 + 工程化开发
前端·javascript·vue.js
infiniteWei14 分钟前
【VIM 入门到精通】视觉模式与剪贴板:高效选择、复制与粘贴
linux·编辑器·vim
追风少年ii15 分钟前
脚本测试--R版本 vs python版本的harmony整合效果比较
linux·python·机器学习·空间·单细胞·培训
沐风。5616 分钟前
css函数
前端·css·css3
infiniteWei17 分钟前
【VIM 入门到精通】精准光标移动与文本对象:Vim思维的进阶
linux·编辑器·vim
tangdou36909865517 分钟前
AI真好玩系列-WebGL爱心粒子手势互动教程 | Interactive Heart Particles with Hand Gestures
前端·人工智能·webgl