四.下面开始在debian 下部署nginx
首先不需要太多包,只需要 pcre, ssl and zlib
aptitude install libpcre3 libpcre3-dev libpcrecpp0 libssl-dev zlib1g-dev
root@houzaicun:/home/nginx-1.0.10# ldconfig -p |grep pcre
libpcreposix.so.3 (libc6,x86-64) => /usr/lib/libpcreposix.so.3
libpcreposix.so (libc6,x86-64) => /usr/lib/libpcreposix.so
libpcrecpp.so.0 (libc6,x86-64) => /usr/lib/libpcrecpp.so.0
libpcrecpp.so (libc6,x86-64) => /usr/lib/libpcrecpp.so
libpcre.so.3 (libc6,x86-64) => /lib/libpcre.so.3
libpcre.so (libc6,x86-64) => /usr/lib/libpcre.so
检查库文件pcre
root@houzaicun:/home# tar -zxvf nginx-1.0.10.tar.gz
root@houzaicun:/home# cd nginx-1.0.10/
root@houzaicun:/home/nginx-1.0.10# ./configure --prefix=/usr/local/nginx-1.0.10
make && make install
useradd -s /usr/sbin/nologin -M www
编辑主配置文件:
root@houzaicun:/www# vim /usr/local/nginx-1.0.10/conf/nginx.conf
user www;
worker_processes 2;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 65325;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
upstream testser1 {
server 192.168.3.107:7000 weight=5;
}
server {
listen 80;
server_name www.hou.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://testser1;
proxy_redirect off;
proxy_set_header Host www.hou.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
index index.html index.htm;
}
}
}
具体解释看 我的nginx学习总结。
http://hzcsky.blog.51cto.com/1560073/502778
这里这个意思是 nginx 80 端口 后端apache7000 。
修改 apache的端口
40 Listen 80 改为7000
重启服务使其生效!
root@houzaicun:/home/nginx-1.0.10# /usr/local/nginx-1.0.10/sbin/nginx
root@houzaicun:/home/nginx-1.0.10# ps -aux |grep nginx
先修改apache 不然 80端口被占用
http://192.168.3.107 测试nginx
http://192.168.3.107:7000/info.php 测试修改后的 apache
nginx反向代理结束
五.awstats日志分析工具安装与配置
软件介绍:
Awstats是一个开源的日志分析工具,它使用Perl语言开发,不仅可用于分析
Apache服务器的访问日志,还可以用于分析samba tomcat squid乃至windows
系统中的IIS等网络服务的日志信息.
Awstats的软件包可发从http://awstats.sourceforg.net下载.
解压并释放awstats软件包,执行目录中的awstats_configure.pl脚本进行安装。
cd /tools
wget http://awstats.sourceforge.net/files/awstats-6.95.tar.gz
tar zxvf awstats-6.95.tar.gz -C /usr/local
mv /usr/local/awstats-6.95 /usr/local/awstats
cd /usr/local/awstats/tools
./awstats_configure.pl
.............................................
1:输入apache的安装路径
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/apache-2.2.21/conf/httpd.conf#这里输入apache的配置文件路径;
2:下面选择y 将httpd服务的日志记录格式改为 "combined",以便记录更多详细信息.
-----> Check and complete web server config file /usr/local/apache-2.2.21/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] ?
3:下面选择 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] ?
4:定义日志分析的目标网站名称(www.hou.com)
-----> 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.hou.com
5:定义awstats配置文件的存放目录(默认为 /etc/awstats/data)
-----> Define config file path
In which directory do you plan to store your config file(s) ?
Default: /etc/awstats
Directory path to store config file(s) (Enter for default):
>/etc/awstats
6:配置完成
-----> Create config file '/etc/awstats/awstats.www.hou.com.conf'
Config file /etc/awstats/awstats.www.hou.com.conf created.
-----> Add update process inside a scheduler
Sorry, configure.pl does not support automatic add to cron yet.
You can do it manually by adding the following command to your cron:
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.hou.com
Or if you have several config files and prefer having only one command:
/usr/local/awstats/tools/awstats_updateall.pl now
Press ENTER to continue...
A SIMPLE config file has been created: /etc/awstats/awstats.www.hou.com.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for 'www.hou.com' with command:
> perl awstats.pl -update -config=www.hou.com
You can also read your statistics for 'www.hou.com' with URL:
> http://localhost/awstats/awstats.pl?config=www.hou.com
Press ENTER to finish...
:修改配置文件
需要在awstats的配置文件中修改所要统计的日志文件的路径.查找"LogFile"配置行并修改为正确位置.
vim /etc/awstats/awstats.www.hou.com.conf
##########################################################################################
#设置httpd logfile的位置 +51
LogFile="/www/logs/aw.log"
#设置要分析的服务日志类型 w表示为web日志 +64
LogType=W
#设置日志格式1表示采用 NCSA apache combined/ELF/XLF log format +123
LogFormat=1
#设置要分析的域名 +154 +169
SiteDomain="www.hou.com"
HostAliases="www.hou.com 127.0.0.1 localhost"
#设置awstats的数据库存放目录
DirData="/usr/local/awstats/data"
#设置DirCgi +213 +223
DirCgi="/usr/local/awstats/wwwroot/cgi-bin"
DirIcons="/usr/local/awstats/wwwroot/icon"
#设置通过浏览器刷新页面 +240
AllowToUpdateStatsFromBrowser=1
##########################################################################################
设置相关目录的权限
mkdir /usr/local/awstats/data
mkdir /www/logs/
touch /www/logs/aw.log
chmod 777 aw.log
:修改httpd.conf配置
vi /usr/local/apache-2.2.21/conf/httpd.conf
##########################################################################################
#Directives to allow use of AWStats as a CGI
Alias /awstatsclasses "/usr/local/awstats/wwwroot/classes/"
Alias /awstatscss "/usr/local/awstats/wwwroot/css/"
Alias /awstatsicons "/usr/local/awstats/wwwroot/icon/"
ScriptAlias /awstats/ "/usr/local/awstats/wwwroot/cgi-bin/"
#This is to permit URL access to scripts/files in AWStats directory.
<Directory "/usr/local/awstats/wwwroot">
Options None
AllowOverride None
Order allow,deny
Allow from all
</Directory>
394 # Virtual hosts
395 Include conf/extra/httpd-vhosts.conf 开启虚拟主机
vim /usr/local/apache-2.2.21/conf/extra/httpd-vhosts.conf
NameVirtualHost 192.168.3.107
<VirtualHost 192.168.3.107>
DocumentRoot "/www"
ServerName www.hou.com
ErrorLog "/www/logs/err.log"
CustomLog "www/logs/aw.log" combined
</VirtualHost>
重启apache
root@houzaicun:/www/logs# perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.hou.com
Create/Update database for config "/etc/awstats/awstats.www.hou.com.conf" by AWStats version 6.95 (build 1.943)
From data in log file "/www/logs/aw.log"...
Phase 1 : First bypass old records, searching new record...
Searching new records from beginning of log file...
Jumped lines in file: 0
Parsed lines in file: 0
Found 0 dropped records,
Found 0 corrupted records,
Found 0 old records,
Found 0 new qualified records.
设置cron计划任务,以便定时运行日志分析程序
echo "5 2 * * * root /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.hou.com" >> /etc/crontab
访问自己的页面2次,然后
http://192.168.3.107/awstats/awstats.pl?config=www.hou.com
出现数据为成功!