初学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

[[email protected] ~]# 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、配置主机名

[[email protected] ~]# cat /etc/sysconfig/network  //查看主机名

NETWORKING=yes

NETWORKING_IPV6=yes

HOSTNAME=web01.tarena.com

3、修改hosts文件

[[email protected] ~]# 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

[[email protected] ~]# service network restart   //重启网络服务

[[email protected] ~]# chkconfig network on     //设置网络服务开机自启

4、软件包的安装

[[email protected] ~]# rpm -q httpd      //查询httpd包有无安装

package httpd is not installed

[[email protected] ~]# yum -y install httpd     //使用yum库安装httpd

5、启动服务

[[email protected] ~]# service httpd restart     //启动httpd服务

[[email protected] ~]# chkconfig httpd on    //设置httpd服务开机自启动

试验二:基本HTTP服务器的配置

Web服务器域名:www.tarena.com

默认首页包括:index.html、index.php

开启保持连接

确认默认httpd是否支持php

网站用老师提供的test_web.zip测试

服务器操作:

1、备份主配置文件

[[email protected] ~]# cd /etc/httpd/conf   //进入主配置文件目录

[[email protected] conf]# cp httpd.conf httpd.conf.bak //备份配置文件防止配置错误后可恢复

2、修改主配置文件

[[email protected] ~]# vim /etc/httpd/conf/httpd.conf  //编辑主配置文件

...

74 KeepAlive On       //保持连接

...

265 ServerName www.tarena.com:80    //web服务器域名

...

391 DirectoryIndex index.html index.php   //默认首页

...

3、启动服务

[[email protected] ~]# service httpd restart     //重启服务

[[email protected] ~]# cd /root/Desktop/

[[email protected] Desktop]# unzip test_web.zip   //解压测试文件

[[email protected] Desktop]# mv jiajutiyan/* /var/www/html/  //将测试网站移动到默认工作目录下

4、编写测试php页面

[[email protected] ~]# 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文件设置参考服务器配置,

[[email protected] ~]# 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、编辑主配置文件

[[email protected] ~]# 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站点

[[email protected] ~]# mkdir /var/www/html/authdir   //新建目录authdir

[[email protected] ~]# echo "http://www.tarena.com/authdir/index.html" >  /var/www/html/authdir/index.html    //输出字符到authdir/index.html

[[email protected] ~]# vim /etc/httpd/conf/httpd.conf  //编辑主配置文件

...

337 <Directory /var/www/html/authdir>

338         Order allow,deny             //设置控制顺序

339         Allow from all               //允许所有用户

340 </Directory>

[[email protected] ~]# service httpd restart   //重启httpd服务

[[email protected] ~]# 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、修改主配置文件

[[email protected] ~]# 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、创建账户密码

[[email protected] ~]# htpasswd -c /etc/httpd/.vuser admin //创建访问用户

New password:    //设置密码

Re-type new password:   //验证密码

Adding password for user admin

3、启动服务测试

[[email protected] ~]# 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、创建测试站点

[[email protected] ~]# mkdir -p /var/www/html/sina.com/bbs  //创建站点

[[email protected] ~]# 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、修改主配置文件

[[email protected] ~]# vim /etc/httpd/conf/httpd.conf  //修改主配置文件

Alias /sina     "/var/www/html/sina.com/bbs"  //全局配置添加别名语句

3、启动服务测试

[[email protected] ~]# service httpd restart   //重启服务

win7客户机测试访问http://www.tarena.com/sina显示This is bbs.sina.com test Page!!!    设置成功

实验六:

查看默认HTTP使用进程管理方式

更改默认进程管理方式为worker模式

[[email protected] ~]# httpd -l    //查看默认进程管理方式

Compiled in modules:

core.c

prefork.c      //默认为prefork

http_core.c

mod_so.c

[[email protected] ~]# cd /usr/sbin/  //进入sbin目录下

[[email protected] sbin]# mv httpd httpd.prefork  //更改http名称

[[email protected] sbin]# mv httpd.worker httpd //将httpd.worker改名为httpd

[[email protected] sbin]# service httpd restart  //重启http服务

[[email protected] sbin]# httpd -l         //查看进程管理方式

Compiled in modules:

core.c

worker.c                      //为worker模式  设置成功

http_core.c

mod_so.c

试验七:

部署Awstats统计Http访问日志

1、安装软件(软件已经拷贝到/usr/src下)

[[email protected] ~]# cd /usr/src/

[[email protected] src]# tar -zxvf awstats-7.1.tar.gz -C /usr/local/  //解压文件

[[email protected] src]# cd /usr/local/

[[email protected] local]# mv awstats-7.1/ awstats   //将文件夹移动到local下并改名

[[email protected] local]# cd awstats/tools/

[[email protected] 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、修改主配置文件

[[email protected] tools]#vim/etc/awstats/awstats.www.tarena.com.conf //编辑awstats主配置文件

...

51 LogFile="/var/log/httpd/access_log"             //修改日志文件路径

[[email protected] tools]# mkdir /var/lib/awstats  //创建文件夹

3、将日志文件导入Awstats

[[email protected] tools]# ./awstats_updateall.pl now    //运行文件导入日志

[[email protected] tools]# crontab -l    //查看周期任务

*/5 * * * * /usr/local/awstats/tools/awstats_updateall.pl now//每5分钟运行一次

[[email protected] tools]# service crond restart //重启周期计划任务服务

[[email protected] tools]# chkconfig crond on

4、验证:

访问下列网址:

http://www.tarena.com/awstats/awstats.pl?config=www.tarena.com可看到网站统计信息

补充:

通过html代码实现网页跳转功能

[[email protected] 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 显示统计信息为设置成功

初学linux网络服务之HTTP服务实验,布布扣,bubuko.com

时间: 2024-08-06 16:04:44

初学linux网络服务之HTTP服务实验的相关文章

初学linux网络服务之vsftp服务实验

实验拓扑: Linux Client -----RHEL5.9(vmnet1)----------(vmnet1) Win7 Client 实验一:测试默认安装vsftpd的结果 匿名用户与本地用户都可以登录 匿名用户登录到/var/ftp,只能下载不能上传 本地用户登录到本地用户的家目录,可以上传和下载 服务器端设置 [[email protected] ~]# cd /misc/cd/Server                 //进入RHEL5.9光盘 [[email protected

初学linux网络服务之samba服务实验

实验拓扑: Linux Client -----RHEL5.9(vmnet1)----------(vmnet1) Win7 Client 实验一:Samba匿名共享 工作组为Tarena 将目录 /usr/src 共享给所有人 共享名设为 tools 允许所有人访问.无需密码验证 访问权限为只读 1.安装软件包 [[email protected] ~]# rpm -q samba-client samba samba-common  //查看安装包 package samba-client

Linux网络服务(深入详解)

本篇结构: 查看网络配置测试网络连接设置网络地址参数建立双网卡 一.查看网络配置 查看所有活动网络接口信息 众所周知,上网需要网卡.在微软环境下,使用ipconfig命令就能查看到该设备的IP地址,而在Linux环境中,则使用: ifconfig命令 //查看本机网络设备信息 其中, ens33--为该设备网卡名称,跟PC机网卡功能相同lo--回环网卡(专门用于自测的网卡,检测TCP服务是否上线)virbr0--虚拟桥接网卡 查看并修改主机名 查看主机名使用"hostname"命令进行

CentOS 7 Linux网络服务 (1)基本网络设置与基本服务

Linux网络设置与基本服务 1.查看及测试网络 查看网络接口信息 ifconfig 查看所有活动网络接口信息 执行 ifconfig 命令 查看指定网络接口信息 ifconfig 网络接口名 查看主机名 执行命令:hostname 更改主机名 执行命令:hostnamectl set-hostnaame + 更改的主机名su 刷新生效 主机名称配置文件 /etc/sysconfig/network 文件保存全局网络配置,主要包括主机名信息在这里配置完成后要小红旗虚拟机,才能使之生效 route

Linux网络服务之HTTP(1)

Linux网络服务之HTTP(1) 实验要求: 1.主机名设为:www.zhy.com,默认首页包括:index.html.index.php,开启保持连接,确认默认httpd是否支持php 2.只允许192.168.1.1访问www.zhy.com,允许所有用户访问www.zhy.com/user/index.html 3.客户端访问/var/www/html/admin/需要输入用户名密码验证 4.客户端访问http://www.zhy.com/bbs时可以访问/var/www/html/u

Linux网络服务13——PXE高效能批量网络装机

Linux网络服务13--PXE高效能批量网络装机 一.PXE简介 PXE:Pre-boot Excution Environment,预启动执行环境 PXE是由Intel公司开发的网络引导技术,工作在Client/Server模式,允许客户机通过网络从远程服务器下载引导镜像,并加载安装文件或者整个操作系统. 若要搭建PXE网络体系,必须要满足以下条件: ·客户机的网卡支持PXE协议(集成BOOTROM芯片),且主板支持网络引导. ·网络中有一台DHCP服务器,以便为客户机分配地址.指定引导文件

Linux网络服务之FTP

Linux网络服务之FTP 实验要求: 1.配置可匿名上传FTP服务.(此需求为纯实验需求,实际环境中一般不使用此功能) 2.配置本地用户访问FTP服务,拒绝匿名用户访问,验证黑白名单,禁锢普通用户nick在自己的主目录里面. 3.更改匿名用户的站点为/ftp/ftp,更改本地用户的站点为/ftp/user,设置匿名用户下载速率50KB/s,本地用户100KB/s,最多20个并发,每IP地址最多2个并发. 实验步骤: 1.安装软件包 搭建FTP服务需要安装vsftpd软件包,使用yum方式安装(

&#8203;Linux网络服务之HTTP(2)

Linux网络服务之HTTP(2) 实验要求: 1.部署基于域名的虚拟主机,当用户访问www.baidu.com的时候访问baidu网站,当用户访问www.sina.com的时候访问sina网站,baidu和sina的ip地址一样,确保前述www.zhy.com访问还能访问 2.部署基于IP的虚拟主机 www.zhy.com192.168.1.253 www.baidu.com192.168.1.12 www.google.com192.168.1.11 实验步骤: (1)基于域名的虚拟主机 1

Linux网络服务之DNS(2)

Linux网络服务之DNS(2) 实验要求: 1.搭建父DNS(zhy.com)服务器,www.zhy.com  -->   192.168.1.253 2.搭建子DNS(bj.zhy.com)服务器,www.bj.zhy.com --> 192.168.1.252 3.在父DNS服务器上配置子域授权 实验步骤: 1.搭建父DNS服务器 (1)安装软件包 略-- (2)修改主配置文件 [[email protected] ~]# cd /var/named/chroot/etc/ [[emai