初学linux网络服务之HTTP服务实验
实验拓扑:
Linux Client
-----RHEL5.9(vmnet1)----------(vmnet1)
Win7 Client
实验一:查看默认HTTP配置
找到默认红帽欢迎页面
(/etc/httpd/conf/httpd.conf ---->Include ----> /etc/httpd/conf.d ----> welcome.conf ----> /var/www/error/noindex.html)
前提条件:
1、配置IP
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 //设置网卡参数
# Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)
DEVICE=eth0
BOOTPROTO=static //静态手动分配地址
ONBOOT=yes
HWADDR=00:0c:29:5d:a8:80
IPADDR=192.168.10.253
NETMASK=255.255.255.0
2、配置主机名
[root@localhost ~]# cat /etc/sysconfig/network //查看主机名
NETWORKING=yes
NETWORKING_IPV6=yes
HOSTNAME=web01.tarena.com
3、修改hosts文件
[root@localhost ~]# cat /etc/hosts //修改host文件,进行地址转换
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
192.168.10.253 web01.tarena.com web01
[root@localhost ~]# service network restart //重启网络服务
[root@localhost ~]# chkconfig network on //设置网络服务开机自启
4、软件包的安装
[root@localhost ~]# rpm -q httpd //查询httpd包有无安装
package httpd is not installed
[root@localhost ~]# yum -y install httpd //使用yum库安装httpd
5、启动服务
[root@localhost ~]# service httpd restart //启动httpd服务
[root@localhost ~]# chkconfig httpd on //设置httpd服务开机自启动
试验二:基本HTTP服务器的配置
Web服务器域名:www.tarena.com
默认首页包括:index.html、index.php
开启保持连接
确认默认httpd是否支持php
网站用老师提供的test_web.zip测试
服务器操作:
1、备份主配置文件
[root@localhost ~]# cd /etc/httpd/conf //进入主配置文件目录
[root@localhost conf]# cp httpd.conf httpd.conf.bak //备份配置文件防止配置错误后可恢复
2、修改主配置文件
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf //编辑主配置文件
...
74 KeepAlive On //保持连接
...
265 ServerName www.tarena.com:80 //web服务器域名
...
391 DirectoryIndex index.html index.php //默认首页
...
3、启动服务
[root@localhost ~]# service httpd restart //重启服务
[root@localhost ~]# cd /root/Desktop/
[root@localhost Desktop]# unzip test_web.zip //解压测试文件
[root@localhost Desktop]# mv jiajutiyan/* /var/www/html/ //将测试网站移动到默认工作目录下
4、编写测试php页面
[root@localhost ~]# vim /var/www/html/test.php
<?php
phpinfo();
?>
测试:
1、在客户端hosts文件指定
192.168.10.253www.tarena.comwww
2、打开浏览器
http://www.tarena.com
http://www.tarena.com/test.php
3、linux客户机验证
ip地址设置和host文件设置参考服务器配置,
[root@svr3 ~]# cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
192.168.10.253 www.tarena.com www
在浏览器中输入www.tarena.com 出现测试网站的主页说明设置成功
访问php显示文件内容,表示默认不支持php
4、win7客户机验证
1)手动设置IP和服务器在同一网段
2)设置hosts文件
C:\Windows\System32\drivers\etc\hosts //修改host文件
localhost name resolution is handled within DNS itself.
#127.0.0.1 localhost
#::1 localhost
192.168.10.253 www.tarena.com www
浏览器访问www.tarena.com 出现测试网站的主页说明设置成功
实验三: 设置只允许 IP地址为192.168.10.21的用户访问www.tarena.com
设置允许所有用户访问www.tarena.com/authdir/index.html
1、编辑主配置文件
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf //编辑httpd主配置文件
...
306 <Directory "/var/www/html"> //站点目录
...
333 Order allow,deny //定义控制顺序
334 # Allow from all //注释掉默认允许所有
335 Allow from 192.168.10.21 //添加只允许此IP访问
336 </Directory>
...
2、新建authdir站点
[root@web01 ~]# mkdir /var/www/html/authdir //新建目录authdir
[root@web01 ~]# echo "http://www.tarena.com/authdir/index.html" > /var/www/html/authdir/index.html //输出字符到authdir/index.html
[root@web01 ~]# vim /etc/httpd/conf/httpd.conf //编辑主配置文件
...
337 <Directory /var/www/html/authdir>
338 Order allow,deny //设置控制顺序
339 Allow from all //允许所有用户
340 </Directory>
[root@localhost ~]# service httpd restart //重启httpd服务
[root@localhost ~]# tail /var/log/httpd/error_log //如遇访问错误可在服务器查看日志
在不同客户端测试
1、在linux客户端测试
1)linux客户机IP地址192.168.10.20 无法访问www.tarena.com,
2)浏览器地址栏输入www.tarena.com/authdir/index.html,可以访问
2、在win7客户端测试(IP192.168.10.21)
1、可以访问www.tarena.com
2、可以访问www.tarena.com/authdir/index.html
试验四:HTTP的用户授权
客户端访问http://www.tarena.com/authdir需要输入用户名密码验证
1、修改主配置文件
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf //编辑主配置文件
...
337 <Directory "/var/www/html/authdir"> //目录
338 Order allow,deny //控制顺序
339 Allow from all //允许所有用户
340 AuthName "Please Input Password!!" //认证领域,弹窗提示
341 AuthType Basic //认证类型
342 AuthUserFile "/etc/httpd/.vuser" //用户数据文件路径
343 Require valid-user //指定授权用户
344 </Directory>
...
2、创建账户密码
[root@localhost ~]# htpasswd -c /etc/httpd/.vuser admin //创建访问用户
New password: //设置密码
Re-type new password: //验证密码
Adding password for user admin
3、启动服务测试
[root@localhost ~]# service httpd restart //重启服务
http://www.tarena.com/authdir
客户及测试:
两台不同客户机访问www.tarena.com/authdir 提示输入用户名密码,输入用户名密码正常访问,说明设置成功
实验五:HTTP目录别名
客户端访问http://www.tarena.com/sina时可以防问/var/www/html/sina.com/bbs下的网页
1、创建测试站点
[root@localhost ~]# mkdir -p /var/www/html/sina.com/bbs //创建站点
[root@localhost ~]# vim /var/www/html/sina.com/bbs/index.html//编辑网页
<html>
<head><title>This is a test Page!!!</title></head>
<body>
<h1>This is bbs.sina.com test Page!!!</h1>
</body>
</html>
2、修改主配置文件
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf //修改主配置文件
Alias /sina "/var/www/html/sina.com/bbs" //全局配置添加别名语句
3、启动服务测试
[root@ser1 ~]# service httpd restart //重启服务
win7客户机测试访问http://www.tarena.com/sina显示This is bbs.sina.com test Page!!! 设置成功
实验六:
查看默认HTTP使用进程管理方式
更改默认进程管理方式为worker模式
[root@localhost ~]# httpd -l //查看默认进程管理方式
Compiled in modules:
core.c
prefork.c //默认为prefork
http_core.c
mod_so.c
[root@localhost ~]# cd /usr/sbin/ //进入sbin目录下
[root@localhost sbin]# mv httpd httpd.prefork //更改http名称
[root@localhost sbin]# mv httpd.worker httpd //将httpd.worker改名为httpd
[root@localhost sbin]# service httpd restart //重启http服务
[root@localhost sbin]# httpd -l //查看进程管理方式
Compiled in modules:
core.c
worker.c //为worker模式 设置成功
http_core.c
mod_so.c
试验七:
部署Awstats统计Http访问日志
1、安装软件(软件已经拷贝到/usr/src下)
[root@localhost ~]# cd /usr/src/
[root@localhost src]# tar -zxvf awstats-7.1.tar.gz -C /usr/local/ //解压文件
[root@localhost src]# cd /usr/local/
[root@localhost local]# mv awstats-7.1/ awstats //将文件夹移动到local下并改名
[root@localhost local]# cd awstats/tools/
[root@localhost tools]# ./awstats_configure.pl //运行文件
...
Config file path ('none' to skip web server setup):
> /etc/httpd/conf/httpd.conf //输入apache的主配置文件
...
-----> Need to create a new config file ?
Do you want me to build a new AWStats config/profile
file (required if first install) [y/N] ? y //生成awstats的配置文件
...
Your web site, virtual server or profile name:
> www.tarena.com //输入你的web服务器名字
...
Default: /etc/awstats
Directory path to store config file(s) (Enter for default):
>
...
/usr/local/awstats/tools/awstats_updateall.pl now
Press ENTER to continue...
...
Press ENTER to finish...
2、修改主配置文件
[root@localhost tools]#vim/etc/awstats/awstats.www.tarena.com.conf //编辑awstats主配置文件
...
51 LogFile="/var/log/httpd/access_log" //修改日志文件路径
[root@localhost tools]# mkdir /var/lib/awstats //创建文件夹
3、将日志文件导入Awstats
[root@localhost tools]# ./awstats_updateall.pl now //运行文件导入日志
[root@localhost tools]# crontab -l //查看周期任务
*/5 * * * * /usr/local/awstats/tools/awstats_updateall.pl now//每5分钟运行一次
[root@localhost tools]# service crond restart //重启周期计划任务服务
[root@localhost tools]# chkconfig crond on
4、验证:
访问下列网址:
http://www.tarena.com/awstats/awstats.pl?config=www.tarena.com可看到网站统计信息
补充:
通过html代码实现网页跳转功能
[root@localhost tools]# vim /var/www/html/awstats.html //编辑awstats.html
<html>
<head><meta http-equiv=refresh content="0; url=http://www.tarena.com/awstats/awstats.pl? config=www.tarena.com">
</head>
<body>
</body>
</html>
验证:
浏览器访问http://www.tarena.com/awstats.html 显示统计信息为设置成功
转载于:https://blog.51cto.com/mmdqx/1427092
初学linux网络服务之HTTP服务实验相关推荐
- linux网络设置与基础服务命令(ifconfig、hostname、route、netstat、ss、ping、traceroute、nslookup、route)
文章目录 linux网络设置与基础服务 前言 查看网络配置 使用ifconfig命令查看网络接口地址 查看指定网络接口信息 使用 hostname命令查看当前主机名称 使用route命令查看路由表条目 ...
- 【Linux网络编程】并发服务器之select模型
00. 目录 文章目录 00. 目录 01. 概述 02. I/O复用技术概述 03. select模型服务器实现思路 04. select模型服务器实现 05. 附录 01. 概述 服务器设计技术有 ...
- 【Linux网络编程】并发服务器之多线程模型
00. 目录 文章目录 00. 目录 01. 概述 02. 多线程服务器 03. 多线程服务器实现思路 04. 多线程服务器实现 05. 附录 01. 概述 服务器设计技术有很多,按使用的协议来分有 ...
- 【Linux网络编程】并发服务器之多进程模型
00. 目录 文章目录 00. 目录 01. 概述 02. 多进程并发服务器 03. 多进程并发服务器实现思路 04. 多进程并发服务器实现 05. 附录 01. 概述 服务器设计技术有很多,按使用的 ...
- 【Linux网络编程】循环服务器之TCP模型
00. 目录 文章目录 00. 目录 01. 概述 02. TCP循环服务器实现方法 03. TCP循环服务器模型 04. TCP循环服务器实现 05. 附录 01. 概述 服务器设计技术有很多,按使 ...
- 【Linux网络编程】循环服务器之UDP循环模型
00. 目录 文章目录 00. 目录 01. 概述 02. UDP循环服务器的实现方法 03. UDP循环服务器模型 04. UDP循环服务器实现 05. 附录 01. 概述 服务器设计技术有很多,按 ...
- Linux网络基础之DNS服务
DNS简介 DNS名词介绍 域名管理系统DNS(Domain Name System)是域名解析服务器的意思,应用层协议,是互联网的一项服务.它在互联网的作用是:把域名转换成网络可以识别的ip地址,在 ...
- Linux网络设置与基础服务
目录 查看网络配置 使用ifconfig命令查看网络接口地址 使用ifconfig命令修改网卡的地址.状态 使用ip/ethtool命令查看网络接口 hostname route命令 使用route命 ...
- Linux网络配置IP地址(初学Linux网络简单配置)
本次配置实验以CentOS 7为例演示网络配置 查看网卡 Ifconfig 查看网关 以VMware Workstation Pro为例 点击编辑→虚拟网络编辑器 进入这个目录 cd /etc/sys ...
最新文章
- ajax 提交订单,php-在Woocommerce 3中通过ajax提交并在结帐时创建订单
- javascript基本类型及类型转换
- crt中 新建的连接存储在哪_连接昌邑路和浦东大道,这条新建道路的规划设计方案公示中...
- 【LeetCode-面试算法经典-Java实现】【054-Spiral Matrix(螺旋矩阵)】
- 在Java EE 7和WildFly中使用Bean验证来验证JAX-RS资源数据
- 第九章 Servlet工作原理解析
- TensorFlow 教程 --教程--2.7字词的向量表示
- Android更新主线程UI的两种方式handler与runOnUiThread()
- java导入包srcy有红叉_eclipse导入web项目之后项目中出现小红叉解决办法
- ipv6的127位掩码如何表示_如何判断两个IP地址是否在同一个网段?什么是子网掩码?...
- H264 编解码协议详解
- win7打开xp共享的计算机,win7系统如何访问xp共享打印机_windows7连接xp共享打印机的方法...
- python求三角形斜边-python 已知三条边求三角形的角度案例
- Javaweb中上传图片,获取相对路径,绝对路径
- java---File类笔记(简单介绍)
- 《二叉平衡树(一)》
- linux查找所有可用的摄像头
- 纯前端利用 js-xlsx 之合并单元格(3)
- 江南大学计算机阶段测试题,江南大学2016.09计算机应用基础(专科类)第2阶段测试题...
- Improving Multimodal Fusion with Hierarchical Mutual InformationMaximization for Multimodal Sentimen