1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
ServerRoot
#服务目录
ServerAdmin
#管理员邮箱
user
#运行服务的用户身份
group
#运行服务的组身份
ServerName
#网站服务器的域名
DocumentRoot
#网页文档的根目录
Listen
#监听的IP地址、端口号
PidFile
#保存httpd进程PID号的文件
DirectoryIndex
#默认的索引页文件
ErrorLog
#错误日志文件的位置
CustomLog
#访问日志文件的位置
LogLevel
#记录日志的级别,默认为warn
Timeout
#网络连接超时,默认为300秒
KeepAlive
#http是否持续连接,可选On或Off
MaxKeepAliveRequests
#保持一个连接的最大请求数
KeepAliveTimeout
#断开连接前的时间
Include
#需要包含进来的其他配置文件
<Directory />
#区域设置
……
<
/Directory
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
<IfModule prefork.c>
StartServers 8
#默认启动8个httpd进程
MinSpareServers 5
#最小的空闲进程数
MaxSpareServers 20
#最大的空闲进程数,如果空闲进程数大于这个值,Apache会自动kill掉一些多余进程
ServerLimit 256
#服务器允许配置进程数的上限
MaxClients 256
#同时最多能发起256个访问,超过的要进入队列等待
MaxRequestsPerChild 4000
#每个进程启动的最大线程数,如达到限制数时进程将结束,如置为0则子线程永不结束
<
/IfModule
>
<IfModule worker.c>
StartServers 4
MaxClients 300
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 0
<
/IfModule
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
[root@www ~]
# mkdir -p /var/www/test1.com /var/www/test2.com
[root@www ~]
# echo "www.test1.com" > /var/www/test1.com/index.html
[root@www ~]
# echo "www.test2.com" > /var/www/test2.com/index.html
[root@www ~]
# vi /etc/httpd/conf/httpd.conf
ServerName 192.168.0.200:80
#设置本机IP地址,不设置会启动报错
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.test1.com
DocumentRoot
/var/www/test1
.com
ServerAlias test1.com
ErrorLog
"/var/www/logs/test1.com-error_log"
CustomLog
"/var/www/logs/test1.com-access_log"
common
<
/VirtualHost
>
<VirtualHost *:80>
ServerName www.test2.com
DocumentRoot
/var/www/test2
.com
ServerAlias test2.com
ErrorLog
"/var/www/logs/test2.com-error_log"
CustomLog
"/var/www/logs/test2.com-access_log"
common
<
/VirtualHost
>
[root@www ~]
# service httpd restart
设置权限
[root@www~]
# chmod -R 750 /var/www/test1.com/ /var/www/test2.com/
[root@www~]
# chgrp -R apache /var/www/test1.com/ /var/www/test2.com/
|
1
2
3
4
5
6
7
8
9
10
|
[root@www~]
# cd /etc/sysconfig/network-scripts/
[root@www network-scripts]
# cp ifcfg-eth0 ifcfg-eth0:0
[root@www network-scripts]
# vi ifcfg-eth0:0
DEVICE=eth0:0
TYPE=Ethernet
ONBOOT=
yes
BOOTPROTO=static
IPADDR=192.168.0.200
GATEWAY=192.168.0.1
NETMASK=255.255.255.0
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
[root@www ~]
# vi /etc/httpd/conf/httpd.conf
NameVirtualHost *:80
<VirtualHost 192.168.0.200:80>
ServerName www.test1.com
DocumentRoot
/var/www/test1
.com
ServerAlias test1.com
ErrorLog
"/var/www/logs/test1.com-error_log"
CustomLog
"/var/www/logs/test1.com-access_log"
common
<
/VirtualHost
>
<VirtualHost 192.168.0.201:80>
ServerName www.test2.com
DocumentRoot
/var/www/test2
.com
ServerAlias test2.com
ErrorLog
"/var/www/logs/test2.com-error_log"
CustomLog
"/var/www/logs/test2.com-access_log"
common
<
/VirtualHost
>
[root@www ~]
# service httpd restart
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
[root@www ~]
# vi /etc/httpd/conf/httpd.conf
NameVirtualHost *:80
Listen 8080
Listen 8081
<VirtualHost *:8080>
ServerName www.test1.com
DocumentRoot
/var/www/test1
.com
ServerAlias test1.com
ErrorLog
"/var/www/logs/test1.com-error_log"
CustomLog
"/var/www/logs/test1.com-access_log"
common
<
/VirtualHost
>
<VirtualHost *:8081>
ServerName www.test2.com
DocumentRoot
/var/www/test2
.com
ServerAlias test2.com
ErrorLog
"/var/www/logs/test2.com-error_log"
CustomLog
"/var/www/logs/test2.com-access_log"
common
<
/VirtualHost
>
[root@www ~]
# service httpd restart
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
[root@www ~]
# vi /etc/httpd/conf/httpd.conf
<VirtualHost *:80>
DocumentRoot
/var/www/test
.com
ServerName www.
test
.com
ServerAlias test1.com
ErrorLog
"/var/www/logs/test.com-error_log"
CustomLog
"/var/www/logs/test.com-access_log"
common
<Directory
"/var/www/html"
>
AuthName
"Please input Password"
#保护领域的提示信息
AuthType basic
#定义使用认证方式,basic或digest
AuthUserFile
/etc/httpd/
.
passwd
#指定认证口令文件的位置
#Require user user1 #授权给指定的一个或多个用户,也可以是一个组:Require group 组名
Require valid-user
#授权给认证口令文件的所有用户
<
/Directory
>
<
/VirtualHost
>
|
1
2
3
4
5
|
[root@www ~]
# htpasswd -c /etc/httpd/.htpasswd user1
New password:
Re-
type
new password:
Adding password
for
user user
[root@www ~]
# service httpd restart
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
[root@www ~]
# vi /etc/httpd/conf/httpd.conf
NameVirtualHost 192.168.0.200
<VirtualHost *:80>
DocumentRoot
/var/www/test
.com
ServerName www.
test
.com
ServerAlias test1.com
ErrorLog
"/var/www/logs/test.com-error_log"
CustomLog
"/var/www/logs/test.com-access_log"
common
<Directory
"/var/www/html"
>
order allow,deny
allow from 192.168.1.0
/24
#all允许所有
<
/Directory
>
<
/VirtualHost
>
[root@www ~]
# service httpd restart
|
1
2
3
4
|
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.
test
.com [NC]
RewriteRule ^(.*)$ http:
//abc
.www.
test
.com
|
1
2
3
|
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)$ http:
//www
.
test
.com/$1 [L,R=301]
|
1
2
3
|
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^news-(.+)\.html$ news.php?
id
=$1
#将news.php?id=123这样的地址转向到news-123.html
|
1
2
3
4
|
ServerName www.
test
.com
DocumentRoot
/var/www/html
ServerName
test
.com
RedirectMatch permanent ^/(.*) http:
//www
.
test
.com/$1
|
1
2
3
4
5
6
7
8
|
[root@www ~]
# yum -y install pcre-devel zlib-devel
[root@www ~]
# useradd -M -s /sbin/nologin nginx
[root@www ~]
# tar zxvf nginx-1.4.2.tar.gz
[root@www ~]
# cd nginx-1.4.2
[root@www nginx-1.4.2]
# ./configure --prefix=/usr/local/nginx \
--user=nginx --group=nginx --with-http_stub_status_module
[root@www nginx-1.4.2]
# make && make install
[root@www nginx-1.4.2]
# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ #设置软链接,方便使用
|
1
2
3
|
nginx -t :检测配置文件语法是否正确
nginx :启动nginx服务
killall -9 nginx :关闭nginx服务
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
[root@www ~]
# vi /etc/init.d/nginx
#!/bin/bash
# chkconfig: 345 99 20
# description: Nginx service control script
PROG=
"/usr/local/nginx/sbin/nginx"
PIDF=
"/usr/local/nginx/logs/nginx.pid"
case
"$1"
in
start)
$PROG
echo
"Nginx service start success."
;;
stop)
kill
-s QUIT $(
cat
$PIDF)
echo
"Nginx service stop success."
;;
restart)
$0 stop
$0 start
;;
reload)
kill
-s HUP $(
cat
$PIDF)
echo
"reload Nginx config success."
;;
*)
echo
"Usage: $0 {start|stop|restart|reload}"
exit
1
esac
[root@www ~]
# chmod +x /etc/init.d/nginx
[root@www ~]
# chkconfig --add nginx
[root@www ~]
# chkconfig nginx on
|
1
2
3
4
|
user nobody;
#默认运行用户,可以编译时指定
worker_processes 1;
#启动工作进程数,一般是cpu的两倍
error_log logs
/error
.log;
#错误日志位置
pid logs
/nginx
.pid;
#pid文件位置
|
1
2
3
|
events {
worker_connections 1024;
#每个进程允许的最大连接数
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
http {
include mime.types;
#设置mime类型(conf/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;
#支持文件发送、下载
keepalive_timeout 65;
#连接保持超时时间
gzip
on;
#开启gzip动态压缩
#配置虚拟主机
server {
listen 80;
server_name localhost;
#设置域名
charset utf8;
#设置网页默认字符集
access_log logs
/host
.access.log main;
#访问日志
location / {
root html;
#网页根目录位置,默认在安装目录html下
index index.html index.htm;
#网站首页
}
error_page 404
/404
.html;
#访问网页不存在或删除,返回的页面
error_page 500 502 503 504
/50x
.html;内部错误返回页面
location =
/50x
.html {
root html;
}
}
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
[root@www nginx]
# vi /usr/local/nginx/conf/nginx.conf #在http{}添加包含虚拟主机配置
include
/usr/local/nginx/vhost/
*.conf;
[root@www nginx]
# vi /usr/local/nginx/conf/vhost/test1.com.conf #创建虚拟主机配置文件
server {
listen 80;
server_name www.test1.com test1.com;
#设置域名
charset utf8;
#设置网页默认字符集
access_log logs
/test1
.com.log main;
#访问日志
location / {
root
/usr/local/nginx/html/test1
.com;
#网页根目录位置
index index.html index.htm;
#网站首页
}
}
|
1
2
3
4
5
6
7
|
server {
listen 80;
server_name www.
test
.com
test
.com;
location / {
rewrite
"^/(.*)$"
http:
//bj
.
test
.com;
}
}
|
1
2
3
4
5
6
|
server {
listen 80;
server_name www.
test
.com
test
.com;
location / {
rewrite ^
/Login/login
.html http:
//www
.
test
.com;
}
|
1
2
3
4
5
6
7
8
9
10
11
|
location ~
/stats
{
root
/usr/local/nginx/html/
;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
/usr/local/nginx/html/
$fastcgi_script_name;
include fastcgi_params;
}
auth_basic
"说明信息"
;
auth_basic_user_file
/usr/local/nginx/
.htpasswds;
}
|
1
2
3
4
5
6
7
|
server {
listen 80;
server_name www.yngx.net yngx.net;
if
(!-e $request_filename)
{
rewrite ^/(.*)$
/index
.php?p=$1 last;
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
#安装gd库
[root@www ~]
# yum install -y gd freetype freetype-devel libpng libpng-devel libjpeg* libxml2 libxml2-devel openssl openssl-devel
[root@www php-5.4]
# tar zxvf php-5.4.tar.gz
[root@www php-5.4]
# ./configure --prefix=/usr/local/php \
-with-config-
file
-path=
/usr/local/php/etc
\
-with-gd --with-zlib --with-iconv --
enable
-zip --
enable
-pdo \
-
enable
-xml --with-openssl --with-curl --
enable
-bcmath --
enable
-
ftp
\
-
enable
-mbstring --
enable
-fpm --with-fpm-user=nginx \
-with-fpm-group=nginx
[root@www php-5.4]
# make && make install
[root@www php-5.4]
# cp php.ini-production /usr/local/php/etc/php.ini
[root@www php-5.4]
# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
[root@www php-5.4]
# chmod +x /etc/rc.d/init.d/php-fpm
[root@www nginx]
# cd /usr/local/nginx
[root@www nginx]
# cp etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf #复制php-fpm配置模板
[root@www nginx]
# vi etc/php-fpm.conf
user = nginx
group = nginx
pid = run
/php-fpm
.pid
pm.start_server = 20
#启动时开启进程数
pm.min_spare_servers = 5
#最小空闲进程数
pm.max_spare_servers = 35
#最多空闲进程数
[root@www php-5.4]
# service php-fpm start
[root@www php-5.4]
# chkconfig php-fpm on
[root@www php-5.4]
# vi /usr/local/nginx/conf/nginx.conf #访问php页面配置段,去掉以下注释
location ~ \.php$ { root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
/usr/local/nginx/html
$fastcgi_script_name;
#SCRIPT_FILENAME后面写网站根目录
include fastcgi_params;
}
|
1
2
3
4
|
[root@www nginx]
# vi html/index.php
<? php
phpinfo();
?>
|
1>.访问量,访问次数,页面浏览量,点击数,数据流量等
2>.
精确到每月、每日、每小时的数据
3>.
访问者国家
4>.
访问者IP
5>.
Robots/Spiders的统计
6>.
访客持续时间
7>.
对不同Files type 的统计信息
8>.
Pages-URL的统计
9>.
访客操作系统浏览器等信息
10>.
其它信息(搜索关键字等等)
1
2
3
4
5
6
7
|
[root@www ~]
# tar zxvf awstats-7.2.tar.gz
[root@www ~]
# mv awstats-7.2 /usr/local/awstats
[root@www ~]
# chown -R root.root /usr/local/awstats/
[root@www ~]
# chmod +x /usr/local/awstats/tools/*.pl
[root@www ~]
# chmod +x /usr/local/awstats/wwwroot/cgi-bin/*.pl
[root@www ~]
# cd /usr/local/awstats/tools/
[root@www tools]
# ./awstats_configure.pl #向导工具,生成网站配置文件
|
1
2
3
4
5
6
7
8
|
[root@www tools]
# vi /etc/awstats/awstats.www.test.com.conf
LogFile=LogFile=
"/var/log/httpd/access_log"
#修改统计网站的日志文件路径
DirData=
"/var/lib/awstats"
#默认日志信息统计数据库
[root@www tools]
# mkdir /var/lib/awstats #创建统计数据库
[root@www tools]
# perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.test.com #为指定网站生成数据
[root@www tools]
# /usr/local/awstats/tools/awstats_updateall.pl now #为所有网站生成数据
[root@www tools]
# crontab -e #设置定时运行日志分析程序
* *
/1
* * *
/usr/local/awstats/tools/awstats_updateall
.pl now
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
[root@www ~]
# vi /etc/httpd/conf/httpd.conf
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/"
<Directory
"/usr/local/awstats/wwwroot"
>
Options None
AllowOverride None
Order allow,deny
Allow from all
<
/Directory
>
[root@www ~]
# service httpd restart
[root@www ~]
# chmod 755 -R /usr/local/awstats
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
[root@www ~]
# mkdir /usr/local/jawstats
[root@www ~]
# tar zxvf jawstats-0.7beta.tar.gz -C /usr/local/jawstats
[root@www ~]
# cd /usr/local/jawstats/
[root@www jawstats]
# cp config.dist.php config.php
[root@www jawstats]
# vi config.php
<?php
//
core config parameters
$sDefaultLanguage =
"zh-cn"
;
#设置默认语言
$sConfigDefaultView =
"thismonth.all"
;
#默认按月显示
$bConfigChangeSites =
true
;
#是否可以更换站点
$bConfigUpdateSites =
true
;
#是否可以更新统计数据
$sUpdateSiteFilename =
"xml_update.php"
;
//
individual site configuration
$aConfig[
"www.test.com"
] = array(
#web站点域名
"statspath"
=>
"/var/lib/awstats"
,
#awstats统计数据目录
"updatepath"
=>
"/usr/local/awstats/wwwroot/cgi-bin/awstats.pl"
,
#用于更新统计数据
"siteurl"
=>
"http://www.test.com"
,
#点击首页标题前往的地址
"sitename"
=>
"www.test.com"
,
#首页标题
"theme"
=>
"default"
,
"fadespeed"
=> 250,
"password"
=>
"123456"
,
#更新统计数据输入的密码
"includes"
=>
""
,
"language"
=>
"zh-cn"
);
?>
|
1
2
3
4
|
[root@www jawstats]
# cd /usr/local/jawstats/languages/
[root@www languages]
# rm -rf ./*
[root@www languages]
# unzip languagepack.zip
[root@www languages]
# rm -rf languagepack.zip
|
1
2
3
4
5
6
7
8
9
|
[root@www ~]
# vi /etc/httpd/conf/httpd.conf
Alias
/tongji
"/usr/local/jawstats"
<Directory
"/usr/local/jawstats"
>
Options Indexes MultiViews
AuthType Basic
AuthName
"Please Login"
AuthUserFile
/etc/httpd/
.
passwd
Require valid-user
<
/Directory
>
|