Linux中搭建HTTP服务器
1、配置IP
[root@localhost~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=static
ONBOOT=yes
HWADDR=00:0c:29:5d:a8:80
IPADDR=192.168.126.133
NETMASK=255.255.255.0
2、配置主机名
[root@localhost~]# cat /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=yes
HOSTNAME=web.gx.com
3、修改hosts文件
[root@localhost~]# cat /etc/hosts
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
192.168.10.253 web.gx.com web
[root@localhost~]# service network restart
[root@localhost~]# chkconfig network on
4、软件包的安装
[root@localhost~]# rpm -q httpd
package httpd is not installed
[root@localhost~]# yum -y install httpd
5、启动服务
[root@localhost~]# service httpd restart
[root@localhost~]# chkconfig httpd on
试验二:基本HTTP服务器的配置
Web服务器域名:www.gx.com
默认首页包括:index.html、index.*
开启保持连接
网站用自己的静态网页musicapp测试
服务器操作:
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.gx.com:80
...
391 DirectoryIndex index.html index.php
...
3、启动服务
[root@localhost ~]# service httpd restart
[root@localhost ~]# chkconfig httpd on
将musicapp文件夹中的文件全部拷贝到/var/www/html/下
4.修改客户端hosts文件
192.168.126.133 www.gx.com
[root@localhost ~]# vim /etc/hosts
5.经测试发现通过本机IP192.168.126.133不能访问,网上查找后删除/etc/httpd/conf.d/welcome.conf
6.打开浏览器访问 http://www.gx.com
3、新建authdir站点,只允许某个IP192.168.126.135访问www.gx.com,允许所有人访问www.gx.com/authdir
[root@web ~]# mkdir /var/www/html/authdir
[root@web ~]# echo "http://www.gx.com/authdir/index.html" > /var/www/html/authdir/index.html
[root@web ~]# 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
在不同客户端测试
[root@localhost ~]# tail /var/log/httpd/error_log
试验四:HTTP的用户授权
客户端访问http://www.gx.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.gx.com/authdir
实验五:HTTP目录别名
客户端访问http://www.gx.com/baidu时可以访问/var/www/html/baidu.com/bbs下的网页
1、创建测试站点
[root@localhost ~]# mkdir -p /var/www/html/baidu.com/bbs
[root@localhost ~]# cat /var/www/html/baidu.com/bbs/index.html
<html>
<head><title>This is a test Page!!!</title></head>
<body>
<h1>This is bbs.baidu.com test Page!!!</h1>
</body>
</html>
2、修改主配置文件
[root@localhost ~]# tail -n 1 /etc/httpd/conf/httpd.conf
Alias /baidu "/var/www/html/baidu.com/bbs"
3、启动服务测试
[root@web01 ~]# service httpd restart
http://www.gx.com/baidu
实验六:查看默认HTTP使用进程管理方式 更改默认进程管理方式为worker模式
[root@localhost ~]# httpd -l
Compiled in modules:
core.c
prefork.c
http_core.c
mod_so.c
[root@localhost ~]# cd /usr/sbin/
[root@localhost sbin]# mv httpd httpd.prefork
[root@localhost sbin]# mv httpd.worker httpd
[root@localhost sbin]# service httpd restart
[root@localhost sbin]# httpd -l
Compiled in modules:
core.c
worker.c
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
[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.gx.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.gx.com.conf
...
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
----------------------------------------------
输入该命令出现错误提示no crontab for root
这个问题非常简单,同样在 root 用户下输入 crontab -e 按 Esc 按: wq 回车
在输入 crontab -l 就没有问题了
主要原因是由于这个liunx服务器 第一次使用 crontab ,还没有生成对应的文件导致的,执行了 编辑(crontab -e)后 就生成了这个文件
----------------------------------------------
[root@localhost tools]# service crond restart
[root@localhost tools]# chkconfig crond on
4、验证:
http://www.gx.com/awstats/awstats.pl?config=www.gx.com
补充:
通过html代码实现网页跳转功能
[root@localhost tools]# cat /var/www/html/awstats.html
<html>
<head><meta http-equiv=refresh content="0; url=http://www.gx.com/awstats/awstats.pl? config=www.gx.com">
</head>
<body>
</body>
</html>
验证:
http://www.gx.com/awstats.html
实验八:基于域名的虚拟主机
www.baidu.com 192.168.126.133 baidu网站
www.sohu.com 192.168.126.133 sohu网站
1、修改主配置文件新建一个配置文件(虚似主机配置专用)
[root@localhost ~]# vim /etc/httpd/conf.d/virt.conf
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /var/www/baidu
ServerName www.baidu.comE
rrorLog logs/www.baidu.com-error_log
CustomLog logs/www.baidu.com-access_log common
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/sohu
ServerName www.sohu.com
ErrorLog logs/www.sohu.com-error_log
CustomLog logs/www.sohu.com-access_log common
</VirtualHost>
创建网站目录和文件
[root@localhost ~]# mkdir /var/www/{baidu,sohu}
[root@localhost ~]# cat /var/www/baidu/index.html
<h1>www.baidu.com</h1>
[root@localhost ~]# cat /var/www/sohu/index.html
<h1>www.sohu.com</h1>
[root@localhost ~]# service httpd restart
验证:先在客户端修改hosts文件
192.168.126.133 www.baidu.com
192.168.126.133 www.sohu.com
实验九:基于端口的虚拟主机
192.168.126.133:8081 baidu网站
192.168.126.133:8082 sohu网站
2、修改主配置文件新建一个配置文件(虚似主机配置专用)
[root@localhost ~]# vim /etc/httpd/conf.d/virt.conf
Listen 8081 //激活端口
Listen 8082
<VirtualHost *:8081>
DocumentRoot /var/www/baidu
ServerName 192.168.126.133
ErrorLog logs/www.baidu.com-error_log
CustomLog logs/www.baidu.com-access_log common
</VirtualHost>
<VirtualHost *:8082>
DocumentRoot /var/www/sohu
ServerName 192.168.10.253
ErrorLog logs/www.sohu.com-error_log
CustomLog logs/www.sohu.com-access_log common
</VirtualHost>
2、启动服务
[root@localhost ~]# service httpd restart
实验十:配置HTTP支持php
1、安装php
[root@localhost ~]# yum -y install php
[root@localhost ~]# cat /var/www/baidu/test.php
<?php //PHP测试页
phpinfo();
?>
[root@localhost ~]# service httpd restart
测试:
http://192.168.126.133:8081/test.php
Linux中搭建HTTP服务器的更多相关文章
- 在linux中搭建git服务器
个人觉得, 以下搭建git服务器的过程就像是在linux增加了一个用户, 而这个用户的登录shell是 git-shell, 太刨根问底的东西我也说不清楚, 还是看下面的过程吧. 过程参考了网上的文章 ...
- Linux中搭建FTP服务器
FTP工作原理 (1)FTP使用端口 [root@localhost ~]# cat /etc/services | grep ftp ftp-data 20/tcp #数据链路:端口20 ftp 2 ...
- Linux中搭建SVN服务器
一 下载工具 1. subversion-1.6.17.tar.gz 2. subversion-deps-1.6.17.tar.gz 二 解压两个包: 1.在此之前,我已经创建了一个用户svnroo ...
- 在Linux中搭建一个FTP服务器
在Linux中搭建一个ftp服务器,以供两个工作小组保管文件使用.禁用匿名.第一个小组使用ftp账号:ftp1,工作目录在:/var/ftp/ftp1:第二个小组使用ftp2,工作目录在:/var/f ...
- Linux中搭建一个ftp服务器详解
来源:Linux社区 作者:luzhi1024 详解Linux中搭建一个ftp服务器. ftp工作是会启动两个通道:控制通道 , 数据通道在ftp协议中,控制连接均是由客户端发起的,而数据连接有两种 ...
- 在Ubuntu中搭建KMS服务器
介绍 基于vlmcsd搭建的KMS服务器. 根据github上的说明,这个工具是用C写的,没有任何依赖,可以直接运行.而且它横跨几乎现在所有的系统平台,如Android, FreeBSD, Solar ...
- Windows中搭建ftp服务器
使用工具Quick Easy FTP Server Windows中搭建FTP服务器有什么用呢? 确实没有用,直到有一次,我在VM中安装了Linux虚拟机,但是文件怎么也上传不到这个虚拟机中. 然后用 ...
- CentOS Linux上搭建PPPoE服务器及拨号设置
CentOS Linux上搭建PPPoE服务器及拨号设置 搭建PPPoE,成功了的话,就觉得超级简单,在CentOS Linux更是5步左右就能搞定. 1.安装pppoe,安装完成后,会有pppoe- ...
- Windows/Linux 环境搭建Git服务器 + vs2012集成git
1. 下载.安装Git 我的系统是Windows 7,需要安装Git for Windows. 下载地址: http://code.google.com/p/msysgit/downloads/lis ...
随机推荐
- 点滴积累【C#】---C#实现上传word将路径保存到数据库,文件保存到服务器。并且按照名称读取服务器的word
效果: 1. . . 数据库: 思路: 上传:先获取word物理地址,然后根据文件的类型判断,然后再保存到相应的文件夹下,再把路径插入到数据库中. 读取:首先根据输入的文件名字在数据库中查找出来文件的 ...
- scut客户端心跳超时和客户端断开测试
1.断开的消息触发后,依然会触发超时 2.触发超时不会触发断开 3.超时会触发多次,断开只触发一次 超时不是很准确,好像有时候不会触发.如果要判断玩家是否下线,可以用最后一次心跳时间判断
- Atitit.减少http请求数方案
Atitit.减少http请求数方案 1. 原理与方法1 1.1. -------jsp1 1.2. "index/js.txt";2 1.3. connReduceDync2 1 ...
- iOS多线程与网络开发之NSURLCache
郝萌主倾心贡献,尊重作者的劳动成果.请勿转载. // 2 // ViewController.m 3 // NSURLCacheDemo 4 // 5 // Created by haomengzhu ...
- DISCUZ开启设计插件功能和显示嵌入点功能
DISCUZ开启设计插件功能和显示嵌入点功能 找到config目录下的config_global.php文件.在最后加入 $_config['plugindeveloper'] = 0; $_conf ...
- 85. Insert Node in a Binary Search Tree【easy】
Given a binary search tree and a new tree node, insert the node into the tree. You should keep the t ...
- Struts2的简单使用
一.准备工作及实例 1.解压struts-2.1.6-all.zip apps目录:struts2自带的例子程序 docs目录:官方文档. lib 目录:存放所有jar文件. Src 目录:源文件存放 ...
- [转]Python定时任务框架APScheduler
APScheduler是基于Quartz的 一个Python定时任务框架,实现了Quartz的所有功能,使用起来十分方便.提供了基于日期.固定时间间隔以及crontab类型的任务,并且可以 持久化任务 ...
- Android Intent 用法全面总结(转载)
1. [代码]调用拨号程序 1 2 3 4 // 给移动客服10086拨打电话 Uri uri = Uri.parse("tel:10086"); Intent intent = ...
- 边缘检测算子和小波变换提取图像边缘【matlab】
Roberts边缘检测算子:根据一对互相垂直方向上的差分可用来计算梯度的原理,采用对角线方向相邻两像素之差. 小波变换的方法比较适用于展现夹带在正常信号中的瞬间反常现象,具有方向敏感性.所以可以边缘检 ...