RedHat6.5 httpd实验的大概步骤
#解包
tar zxf httpd-2.2.17.tar.gz -C /usr/src
#切换到目录
cd /usr/src/httpd-2.2.17/
#编译
./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi && make && make install
#确认安装结果
ls /usr/local/httpd/
#优化执行路径
ln -s /usr/local/httpd/bin/* /usr/local/bin/
ls -l /usr/local/bin/httpd /usr/local/bin/apachectl
#查看版本
httpd -v
#添加httpd系统服务
cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
vi /etc/init.d/httpd
#!/bin/sh
# chkconfig: 35 85 15
# description: Startup script for the Apache HTTP Server
chkconfig --add httpd
chkconfig --list httpd
#配置域名解析
IP
192.168.174.130
网站名称
www.benet.com
/etc/hosts修改配置文件
#配置httpd.conf
vim /usr/local/httpd/conf/httpd.conf
97行
ServerName www.benet.com
#检查
/usr/local/httpd/bin/apachectl -t
Syntax OK
#启动httpd服务
[root@lianxi httpd-2.2.15]# /etc/init.d/httpd start
[root@lianxi httpd-2.2.15]# netstat -anpt |grep httpd
tcp 0 0 :::80 :::* LISTEN 54646/httpd
#部署网页文档
[root@lianxi httpd-2.2.15]# cat /usr/local/httpd/htdocs/index.html
<html><body><h1>It works!</h1></body></html>
#在网页*问
www.benet.com
#查看日志
tail /usr/local/httpd/logs/access_log
登陆信息等
tail /usr/local/httpd/logs/error_log
故障日志 notice是告警
#全局配置
ServerRoot 服务器根目录
Listen 设置监听端口
User 设置运行httpd进程时用户身份
Group设置运行httpd进程时组身份
ServerName 设置web站点
ServerAdmin设置管理员E-mail地址
DocumentRoot 设置网站站点目录
Directorylndex 设置网站默认的索引页(首页)可设置多个首页文件 以空格分开
ErrorLog 设置错误日志文件的路径
LogLevel 设置记录日志的级别路径 默认级别为warn(警告)
CustomLog 设置访问日志路径类型 common(通用格式)
PidFile 设置用于保存httpd进程号(PID)的文件
CharsetDefault 设置字符集
Include 包含一个配置文件内容,可以将一些特殊功能配置放到一个单独的文件中
再将Include配置项将其包含到httpd.conf这样便于独立配置功能的维护而不影响主配置文件
#区域配置
114行
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
Options:配置在特定目录使用哪些特性,常用的值和基本含义如下:
FollowSymLinks: 在该目录下允许文件系统使用符号连接。
AllowOverride:允许存在于.htaccess文件中的指令类型(.htaccess文件名是可以改变的,其文件名由AccessFileName指令决定):
Order:控制在访问时Allow和Deny两个访问规则哪个优先:
Allow:允许访问的主机列表(可用域名或子网,例如:Allow from 192.168.0.0/16)。
Deny:拒绝访问的主机列表。
Deny from all禁止访问
#安装AWStats分析系统
wget http://awstats.sourceforge.net/files/awstats-7.2.tar.gz
tar zxf awstats-7.3.tar.gz
mv awstats-7.3 /usr/local/awstats
#创建配置文件
cd /usr/local/awstats/tools/
chmod +x awstats_configure.pl
./awstats_configure.pl
#指定httpd主配置文件的路径
----- AWStats awstats_configure 1.0 (build 1.9) (c) Laurent Destailleur -----
This tool will help you to configure AWStats to analyze statistics for
one web server. You can try to use it to let it do all that is possible
in AWStats setup, however following the step by step manual setup
documentation (docs/index.html) is often a better idea. Above all if:
- You are not an administrator user,
- You want to analyze downloaded log files without web server,
- You want to analyze mail or ftp log files instead of web log files,
- You need to analyze load balanced servers log files,
- You want to 'understand' all possible ways to use AWStats...
Read the AWStats documentation (docs/index.html).
-----> Running OS detected: Linux, BSD or Unix
-----> Check for web server install
Enter full config file path of your Web server.
Example: /etc/httpd/httpd.conf
Example: /usr/local/apache2/conf/httpd.conf
Example: c:\Program files\apache group\apache\conf\httpd.conf
Config file path ('none' to skip web server setup):
> /usr/local/httpd/conf/httpd.conf
#设置文件类型
-----> Check and complete web server config file '/usr/local/httpd/conf/httpd.conf'
Warning: You Apache config file contains directives to write 'common' log files
This means that some features can't work (os, browsers and keywords detection).
Do you want me to setup Apache to write 'combined' log files [y/N] ? y
-----> Update model config file '/usr/local/awstats/wwwroot/cgi-bin/awstats.model.conf'
File awstats.model.conf updated.
-----> 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
#指定web站点创建配置文件
-----> Define config file name to create
What is the name of your web site or profile analysis ?
Example: www.mysite.com
Example: demo
Your web site, virtual server or profile name:
> www.benet.com
回车
#修改站点统计配置文件
vim /etc/awstats/awstats.www.benet.com.conf
51行
LogFile="/usr/local/httpd/logs/access_log"
204行
DirData="/var/lib/awstats"
#创建目录
mkdir /var/lib/awstats
#执行日志分析,并设置cron任务计划
chmod +x awstats_updateall.pl
./awstats_updateall.pl now
crontab -e
crontab -l
*/5 * * * * /usr/local/awstats/tools/awstats_updateall.pl now
[root@lianxi tools]# /etc/init.d/crond start
[root@lianxi tools]# chkconfig --level 35 crond on
#访问AWStats
为了访问简单我们可以编辑一个配置文件
[root@lianxi tools]# vim /usr/local/httpd/htdocs/awb.html
<html>
<head>
<meta http-equiv=refresh content="0;
url=http://www.benet.com/awstats/awstats.pl?config=www.benet.com">
</head>
<body></body>
</html>
mkdir /var/www/html/accpcom -p
mkdir /var/www/html/benetcom -p
echo "<h1>www.benet.com</h1>" > /var/www/html/benetcom/index.html
echo "<h1>www.accp.com</h1>" > /var/www/html/accpcom/index.html
[root@httpd benetcom]# vim /etc/hosts
192.168.174.101 www.benet.com www.accp.com
127.0.0.1 httpd
基于域名的虚拟主机配置:
[root@httpd benetcom]# vim /usr/local/httpd/conf/extra/httpd-vhosts.conf
<Directory "/var/www/html"> 手动添加
Order allow,deny
Allow from all
</Directory>
NameVirtualHost 192.168.174.101 修改IP地址
<VirtualHost 192.168.174.101>
DocumentRoot "/var/www/html/benetcom" 指定网页根目录
ServerName www.benet.com
ErrorLog "logs/www.benet.com.error_log"
CustomLog "logs/www.benet.com.access_log" common
</VirtualHost>
<VirtualHost 192.168.174.101> 修改IP地址
DocumentRoot "/var/www/html/accpcom" 指定网页根目录
ServerName www.accp.com
ErrorLog "logs/www.accp.com.error_log"
CustomLog "logs/www.accp.com.access_log" common
</VirtualHost>
[root@httpd benetcom]# vim /usr/local/httpd/conf/httpd.conf
ServerName localhost:80
Include conf/extra/httpd-vhosts.conf 388行 把#去掉
/usr/local/httpd/bin/apachectl -t 检查语法
/usr/local/httpd/bin/apachectl restart 重启服务
####登录访问....