try nginx

platform: Linux peterguo 2.6.31.5-0.1-desktop #1 SMP PREEMPT 2009-10-26 15:49:03 +0100 x86_64 x86_64 x86_64 GNU/Linux

download: http://nginx.org/download/ ->http://nginx.org/download/nginx-1.3.9.tar.gz

depends: prec, ssl, etc , use yast2 to install

install: tar xf xxx; ./configure ; make ; make install

configuration: vi /usr/local/nginx/conf/nginx.conf  remove some "#" and add some format like this:


log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"'
                  '"$Cookie_usr" "$Cookie_age"';


access by python:urllib2.urlopen(urllib2.Request("http://192.168.1.105:80/index.html", None, {"cookie":"usr=peterguo;age=29"}))

check logs: tail access.log

192.168.1.105 - - [15/Mar/2013:00:01:44 +0800] "GET /index.html HTTP/1.1" 200 612 "-" "Python-urllib/2.6" "-""peterguo" "29"

1.解决nginx if 逻辑与问题

location / {
    empty_gif;
    expires -60;
    set $flag 0;

    if ( $http_referer ~ "^http://www.xxx.com") {
        set $flag "${flag}1";
    }
    if ( $request_uri ~ "srctype=xxx") {
        set $flag "${flag}2";
    }
    if ( $flag = "012" ) {
        access_log  /data/nginx-logs/pingd/web/access_log pr_fmt;
    }
    add_header Cache-Control no-store;
    add_header Cache-Control private;
}

2.正则表达式检测

#/usr/local/nginx/sbin # pcretest [回车]
PCRE version 6.4 05-Sep-2005

  re> "^ABC"    [回车]
data> "ABCD"    [回车]
No match
data> ABCDEF    [回车]
 0: ABC
data> aABC  [回车]
No match
data>   [Ctrl-C 退出]
3. 切割日志
logs_path="/data/apache2-logs/"
errorlogs_path="/data/logs/"
TM=`date +"%Y%m%d%H%M00" -d "5 min ago"`
ip=`/sbin/ifconfig eth1 | grep "inet addr" | awk '{print $2}' | cut -c 6-`
for domain in `ls ${logs_path}/*-access_log | awk -F "/" '{print $NF}' | cut -d"-" -f1`;do
        if ! [ -f ${logs_path}$domain-${TM}_$ip.log ];then
                mv ${logs_path}$domain-access_log ${logs_path}$domain-${TM}_$ip.log
        fi
done
if [ -f ${logs_path}access_log ];then
        mv ${logs_path}access_log ${logs_path}${TM}_$ip.log
fi


for domain in `ls ${errorlogs_path}/*-error_log | awk -F "/" '{print $NF}' | cut -d"-" -f1`;do
        if ! [ -f ${errorlogs_path}$domain-error_$TM ];then
                mv ${errorlogs_path}$domain-error_log ${errorlogs_path}$domain-error_$TM.log
        fi
        if ! [ -f ${errorlogs_path}$domain-access_$TM ];then
                mv ${errorlogs_path}$domain-access_log ${errorlogs_path}$domain-access_$TM.log
        fi
done
kill -USR1 `cat /usr/local/nginx/logs/nginx.pid`


find /data/logs -maxdepth 1 -mmin +180 | grep "access" | xargs -i rm {}
find /data/logs -maxdepth 1 -mtime +1 | grep "error" | xargs -i rm {}

你可能感兴趣的:(try nginx)