-
Nginx日志切割脚本
Posted on 一月 9th, 2009 No comments使用logrotate:
vi /etc/logrotate.d/nginx
/usr/local/nginx/logs/*.access.log error.log{
daily
missingok
#保留365个log
rotate 365
compress
#延后压缩
delaycompress
#无文件不压缩
notifempty
#创建的文件权限设置为644,用户组nobody:root
create 644 nobody root
#多个文件脚本轮换只执行一次
dateext
#在文件末尾添加当前日期
olddir /usr/local/nginx/logs/backlog/
#把备份文件拷贝到老目录,防止再次备份
sharedscripts
prerotate
#rotate之前sleep59秒
sleep 59
endscript
postrotate
if [ -f /var/run/nginx.pid ]; then
kill -USR1 `cat /var/run/nginx.pid`
fi
/usr/local/awstats/tools/awstats_buildstaticpages.pl -update -config=www.sasacity.com -dir=/app/public/awstats/data/ -lang=cn -configdir=/usr/local/awstats/wwwroot/cgi-bin/ -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl
endscript
}
调试脚本用
/usr/sbin/logrotate -d /etc/logrotate.d/nginx
使用无误后执行一下看看
/usr/sbin/logrotate -f /etc/logrotate.d/nginx
如果执行没有问题,编辑 /etc/crontab,把cron.daily的运行日期改到每天晚上23点59分执行(注意到我们在脚本中sleep了59秒):
59 23 * * * root run-parts /etc/cron.daily这个方法的缺点是dateext无法自动定制格式,如果文件很多,我们需要放在2008/05/, 2008/06/, 2008/07/这样的目录结构,因此我编写了以下脚本,供参照:
vi /usr/local/nginx/sbin/cut_nginx_log.sh
logs_path="/usr/local/nginx/logs/"
logfiles="www.access.log blog.access.log host.access.log error.log"server=`hostname`
date=$(date -d "yesterday" +"%Y%m%d")
save_path=${logs_path}/$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")
mkdir -p ${save_path}for log in ${logfile};
do mv ${logs_path}/${log} ${save_path}/${log}.${date}.${server};
donekill -USR1 `cat /var/run/nginx.pid`
for log in ${logfile};
do gzip ${save_path}/${log}.${date}.${server};
done
添加cronjob
crontab -e
0 0 * * * /bin/bash /usr/local/nginx/sbin/cut_nginx_log.sh -
Nginx下设置运行Awstats
Posted on 一月 9th, 2009 No comments还没有安装awstats的先安装配置awstats。由于Nginx目前的稳定版本0.6.34对perl和fastcgi的支持还不是很好。所以有2种方案在nginx下使用awstats. 1. 用awstats静态发布;2. 安装nginx的perl fastcgi。推荐第一种方式。
无论使用那种方式,首先必须先要把nginx的默认log格式改成和apache的combine格式相同:log_format main ‘$remote_addr – $remote_user [$time_local] ‘
‘”$request” $status $body_bytes_sent “$http_referer” ‘
‘”$http_user_agent” “$http_x_forwarded_for”‘;然后在awstats的配置文件中加入以下:
LogFormat=”%host %other %logname %time1 %methodurl %code %bytesd %refererquot %uaquot %otherquot”
建立logrotate,这个部分我们假设用静态生成的方式
vi /etc/logrotate.d/nginx
/usr/local/nginx/logs/access.log {
daily
missingok
rotate 52
compress
delaycompress notifempty
create 644 nginx root sharedscripts
prerotate
/usr/local/awstats/tools/awstats_buildstaticpages.pl -update -config=www.abc.com -dir=/app/public/awstats/data/ -lang=cn -configdir=/usr/local/awstats/wwwroot/cgi-bin/ -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl
#/usr/local/awstats/wwwroot/cgi-bin/awstats.pl --config=www.abc.com -update
endscript
postrotate
if [ -f /var/run/nginx.pid ]; then
kill -USR1 `cat /var/run/nginx.pid`
fi
endscript
}logrotate由cron执行, 需要编辑 /etc/crontab
将cron.daily的执行时间设置为0 0 * * *分
使用nginx的cgi配置需要先让perl的fastcgi方式运行并在后台侦听socket或端口,nginx的官方wiki中有一篇介绍如何编写这个脚本,其中需要把/opt/nginx/fcgi/cgi.sock修改成/var/run/fcgi.sock。这里很重要的一点是设置/var/run/fcgi.sock,我有一次就是因为这个问题,没有能运行起来
chown nobody:nobody /var/run/fcgi.sock
/usr/local/bin/cgiwrap-fcgi.pl &如果不能运行,先安装perl的FCGI和FCGI::ProcManager模块
perl -MCPAN -e 'install FCGI'
perl -MCPAN -e 'install FCGI::ProcManager'
如果可以运行了,那perlfastcgi已经在后台运行了,现在配置nginx.conf来支持perl
location ~ .*\.pl$ {
gzip off; #gzip makes scripts feel slower since they have to complete before getting gzipped
fastcgi_pass unix:/var/run/fcgi.sock;
fastcgi_index awstats.pl;
include fastcgi_params;
}据nginx wiki的说明,现在这段代码,但是还是很ugly,可见还并不stable。英文不好的网管可以看这篇中文翻译,只要按着一步执行就可以了。下面给出完整nginx.conf中awstats的server配置:
server {
listen 80;
server_name wa.mysite.com;
access_log logs/wa.access.log main;
root /usr/local/awstats/wwwroot/cgi-bin/;
auth_basic “Restricted”;
auth_basic_user_file sasabrand.pass;location / {
index awstats.pl?config=www.mysite.com;
}location ~ .*\.pl?$ {
gzip off; #gzip makes scripts feel slower since they have to complete before getting gzipped
fastcgi_pass unix:/var/run/fcgi.sock;
fastcgi_index awstats.pl;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_read_timeout 60;
include fastcgi_params;
}location ~ .*\.php?$ {
fastcgi_pass 127.0.0.1:1026;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
} -
Web日志分析
Posted on 一月 8th, 2009 No comments打印所有IP, 并按IP排序
cat 1.log |awk ‘{print $1}’| sort | uniq -c |sort -nr |less
然后用 ip地址查询or ip-adress.cm,决定是否 deny 掉。在 ubuntu 下直接使用
whois xxx.xxx.xxx.xxx统计网站被Google和百度索引的情况:
#!/bin/sh
YESTERDAY=`date -d yesterday +%y%m%d`
LOG_PATH=’/home/apache/logs’
grep -i Googlebot $LOG_PATH/access_log|awk ‘{print $7}’ |sort -u>spider/$YESTERDAY.googlebot.txt
grep -i baiduspider $LOG_PATH/access_log|awk ‘{print $7}’ |sort -u>spider/$YESTERDAY.baiduspider.txtawk ‘$4 ~/^\[08\/Jan\/2008/(print $0}’ 1.log 打印2008年1月4日的日志
awk ‘$9 == “200″ || $10 < 20 && $1 != 58\.37\.170\.231′ 1.log 如果返回代码不是200或者返回数据少于20并且非内网用户,则返回log
awk学习笔记,awk编程学习笔记 -
Awstats安装和配置
Posted on 一月 8th, 2009 No comments目前我同时使用awstat和google analytics,他们各有优劣:GA的报表相对全面而美观但是定制麻烦,而awstats由于是基于网站日志的分析,所以相对来说比较准确; 另外awstats能比较有效的获得搜索引擎bots的最近访问时间,这对seo也是很有帮助的,由于GA是用js方式的,而搜索引擎的bot都会忽略js, 因而GA是无法获得搜索引擎bots相关信息的。
安装
下载安装最新的awstats:
cd /home/software
wget http://prdownloads.sourceforge.net/awstats/awstats-6.9.tar.gz
tar -xvzf awstats-6.9.tar.gz
mv awstats-6.9 /usr/local/awstats
cd /usr/local/awstats
mkdir -m 755 data配置Awstats
cd /usr/local/awstats/tools
perl awstats_configure.pl
我们这里假设conf文件配置在/usr/local/awstats目录下。更新数据库
perl awstats.pl -config=www.jefflei.com -update
如果成功看到结果,可以将以上命令放到crontab中执行,每天8点10分执行更新:
10 8 * * * /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.xyz.com >/dev/null 2>&1Awstats的高级配置
安装GeoIP
编译安装GeoIP的C应用库:
wget http://geolite.maxmind.com/download/geoip/api/c/GeoIP.tar.gz
tar -xvzf GeoIP.tar.gz
cd GeoIP
./configure
make;make install
安装Perl下的Geo IP应用
perl -MCPAN -e 'install "Geo::IP"'然后下载GeoIP数据库,具体介绍如何自动下载ip数据库和纯真国内数据库请见我另外一篇博文:
cd /usr/local/share/GeoIP/
wget -t 5 http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
wget -t 5 http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
wget -t 5 http://geolite.maxmind.com/download/geoip/database/asnum/GeoIPASNum.dat.gz
gzip -d *
修改awstats的配置文件,添加如下几行:
LoadPlugin="decodeutfkeys"
LoadPlugin="toolstips"
LoadPlugin="geoip GEOIP_STANDARD /usr/local/share/GeoIP/GeoIP.dat"
LoadPlugin="geoip_city_maxmind GEOIP_STANDARD /usr/local/share/GeoIP/GeoLiteCity.dat"
LoadPlugin="geoip_org_maxmind GEOIP_STANDARD /usr/local/share/GeoIP/GeoIPASNum.dat"
#百万级以上网址使用:LoadPlugin="hashfiles"更新搜索引擎定义
对于中文网页,参照车东blog中介绍的中文搜索引擎定义:
wget http://www.chedong.com/tech/lib.tgz
解压后将search_engine.pm, robots.pm覆盖/usr/local/awstats/wwwroot/cgi-bin/lib/目录下的原文件使用多awstats配置文件
多个站点很多配置选项是重复的,如果每个配置文件都修改维护起来会很麻烦,AWStats提供了配置文件包含的功能,我们使用一个通用配置:awstats.common.conf。这样每个配置文件只要include这个common设置就可以了:
awstats.www.abc.com.conf:
Include "awstats.common.conf"
LogFile="/usr/local/nginx/logs/access_log.store.%NS"
#压缩文件用 LogFile="zcat /home/www/logs/%YYYY/%MM/www.access.log.%YYYY-24%MM-24%DD-24.gz|" 效率比gzip高
SiteDomain="www.abc.com"
HostAliases="abc.com www.abc.com 127.0.0.1 localhost"
awstats.help.abc.com.conf:
Include "awstats.common.conf"
LogFile="/usr/local/apache/logs/access_log.help.%NS"
SiteDomain="help.abc.com"
AWStats自带了批处理工具tools/awstats_updateall.pl,可以批量地遍历一个目录下所有地配置文件并运行统计, 更新cron脚本如下:
10 8 * * * /usr/local/awstats/tools/awstats_updateall.pl now -configdir=/usr/local/awstats/wwwroot/cgi-bin/ >>/usr/local/awstats/logs/cronaw.log 2>>/usr/local/awstats/logs/cronaw.errAwstats, Google Analytics, WebAlizer访问统计数据相差很大的问题
这种情况一般是由于被统计的数据不同所造成的,
首先,在awstats配置文件中设置不被统计的文件:
NotPageList="css js class gif jpg jpeg png bmp ico swf pdf txt zip arj rar gz z bz2 wav mp3 wma mpg avi"
在webAlizer中,可以修改PageType 配置。另外,Awstats的页面数包括了ajax请求的页面和include页面,而一般这些页面并不会种GA代码,因此这部分的差异也许会很大, 参见我另一篇如何更精确统计awstats差异页面的文章。
使用准确的中国ip数据库
见刘晖博客,awstats安装QQip数据库。安装后如果还有问题可以安装perl的Net::XWhois
perl -MCPAN -e ‘install Net::XWhois’
安装无误后可根据需要设定系统自动更新IP数据库。
extra的编写
推荐几个有用的AWStats Extra扩展统计, 包括获取搜索引擎最近访问时间,抓取地图,还有RSS的访问等,对我们了解搜索引擎bot的动向和RSS用户很有帮助。参见车东关于RSS的一些说明
调整Bots定义
这里介绍了在哪里找robots的定义,参见 DBANotes的这篇关于114的说明
多服务器的日志合并分析
只要你的文件系统没有使用NFS,就需要把不同服务器上的log文件同步到一台上合并分析,合并之前还需要排序以提高awstats的效率
第一步,用rsync同步文件
#!/bin/sh
rsync -avz --progress -e "ssh -p 22" www@10.0.0.1/data/logs/`date --date "1 days ago" +*.\%Y\%m\%d` /data/logs/在原服务器上删除前一天的日志:
50 4 * * * /bin/rm -f /data/logs/`date --date "1 days ago" +*.\%Y\%m\%d`第二步,分析日志,假设我们有3台服务器的日志传到第四台服务器上合并日志:
-rw-r--r-- 1 nobody root 1538516677 Oct 29 05:20 www.access.log.1.gz
-rw-r--r-- 1 nobody root 1507444445 Oct 29 04:12 www.access.log.2.gz
-rw-r--r-- 1 nobody root 1507444445 Oct 29 04:43 www.access.log.3.gz我们利用logresolvemerg.pl配置文件中配置日志处理
LogFile="/usr/local/awstats/tools/logresolvemerge.pl /usr/local/nginx/logs/www.access.log.* |"
logresolve可以合并、排序日志文件,它还自动检测文件格式,只要zcat或bzcat在PATH中,它会自动调用zcat -
ZF Compatible Suhosin Setup
Posted on 一月 4th, 2009 No comments需要使用ZendFramework,建议在php.ini中对suhosin的设置如下:
suhosin.mail.protect = 0
suhosin.memory_limit = 128M
suhosin.post.max_vars = 500
suhosin.post.max_value_length = 325000
suhosin.request.max_vars = 500
suhosin.session.cryptua = off -
软件使用和目录设置规范
Posted on 十二月 31st, 2008 No comments常用系统程序操作
mysql关闭和启动
/bin/sh /usr/local/mysql/bin/mysqld_safe --user=mysql &
FastCGI启动和关闭
ulimit -SHn 51200
/usr/local/sbin/php-fpm start|stop|restart|reload|quit|logrotate
NGINX启动和关闭
/usr/local/webserver/nginx/sbin/nginx
重载nginx配置
kill -HUP 'cat /var/run/nginx.pid'
调试配置文件
nginx -t -c /etc/nginx/nginx.conf
nginx接受的信号
TERM, INT 快速关闭
QUIT 从容关闭
HUP 重载配置,用新的配置开始新的工作进程从容关闭旧的工作进程
USR1 重新打开日志文件
USR2 平滑升级可执行程序。
WINCH 从容关闭工作进程
memcached启动和关闭
/usr/local/bin/memcached -m 64m -l 127.0.0.1 -p 11211 -d -u root -P /var/run/memcached.pid -c 128 -vv
kill 'cat /var/run/memcached.pid'
配置开机自启时执行程序:修改/etc/rc.local
系统程序文件目录规范
mysql目录 /usr/local/mysql
mysql数据文件 /usr/local/data
mysql soketfile /tmp/
mysql配置文件 /etc/my.cnfphp目录 /usr/local/
php-config目录 /usr/local/bin/php-config
php.ini /etc/php.ini
eAccelorator Cache /var/cache/eaccelerator_cache
php fastcgi执行文件 /usr/local/sbin/php-fpm
php fastcgi配置文件 /usr/local/etc/php-fpm.conf
php fastcgi日志 /usr/local/logs/php-fpm.log
php fastcgi pid文件 /usr/local/logs/php-fpm.pid
fastcgi接口(TCP方式) /tmp/php-cgi.sock
php扩展文件目录 /usr/local/lib/php/extensions/no-debug-non-zts-20060613/nginx目录 /usr/local/nginx
nginx /var/log/nginx
nginx配置文件 /usr/local/nginx/conf/nginx.conf
nginx pid文件 /var/run/nginx.pid
nginx logrotate文件 /usr/local/nginx/sbin/cut_nginx_log.sh
web文件目录 /app/
系统启动执行文件 /etc/rc.local
sysctl文件 /sbin/sysctl
sysctl配置文件 /etc/sysctl.confmemcached /usr/local/bin/memcached
memcached PID文件 /var/run/memcached.pid -
Memcached安装和使用
Posted on 十二月 31st, 2008 No commentsMemcached安装
Memcached需要libevent,所以需要先安装libevent
wget "http://www.monkey.org/~provos/libevent-1.4.9-stable.tar.gz"
./configure --prefix=/usr/
make;make install
安装后libevent在/usr/libs目录下wget http://www.danga.com/memcached/dist/memcached-1.2.6.tar.gz
./configure --with-libevent=/usr/
make;make install
安装后memcached默认在/usr/local/bin/目录下Memcached使用
这篇memcache的使用是介绍不错,下面简介一下启动和关闭:
启动
/usr/local/bin/memcached -m 64m -l 127.0.0.1 -p 11211 -d -u root -P /var/run/memcached.pid -c 128 -vv
选项 说明 -p 使用的TCP端口。默认为11211 -m 最大内存大小。默认为64M -vv 用very vrebose模式启动,调试信息和错误输出到控制台 -d 作为daemon在后台启动 -c 最大运行的并发连接数,默认是1024,按照服务器的负载量来设定 -P 设置保存Memcache的pid文件 -l 监听的服务器IP地址,如果有多个地址的话 -u 运行Memcache的用户,默认不能用root启动,所以当前用户为root用户时,需要用-u参数来指定 关闭
kill 'cat /var/run/memcached.pid'测试连接
$ telnet localhost 11211
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
set foo 0 0 3 (保存命令)
bar (数据)
STORED (结果)
get foo (取得命令)
VALUE foo 0 3 (数据)
bar (数据) -
安装phpMyadmin3.1.1
Posted on 十二月 20th, 2008 1 commentwget http://prdownloads.sourceforge.net/phpmyadmin/phpMyAdmin-3.1.1-all-languages.tar.gz?download
tar -xvzf phpMyAdmin-3.1.1-all-languages.tar.gz
cp phpMyAdmin-3.1.1-all-languages /app/public/data/pma311
cp config.sample.inc.php config.inc.phpvi config.inc.php找到 blowfish_secret, 设置加密秘钥. 然后可以直接设定$cfg['Servers'][$i]['controluser'] ,$cfg['Servers'][$i]['controlpass'] ;也可以由第一次登陆后由phpMyadmin自动设置。
在webserver中为pma目录建立密码
htpasswd -c /usr/local/nginx/conf/.htpasswd nginx
输入两遍密码后创建密码文件.htpasswd,然后在nginx的server中增加如下两行
auth_basic ‘Restricted’;
auth_basic_user_file .htpasswd; -
nginx简单配置文件
Posted on 十二月 19th, 2008 No commentsuser nobody;
worker_processes 1;
error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid /var/run/nginx.pid;
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 51200;
}
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 60;
tcp_nodelay on;
gzip_static on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 8k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_vary on;
gzip_proxied any;
# Some version of IE 6 don't handle compression well on some mime-types,
# so just disable for them
gzip_disable "MSIE [1-6].(?!.*SV1)";
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
include /usr/local/nginx/conf/vhosts/*;
server {
listen 80;
server_name www.leizhenfang.com;
root /app/public/www;
#charset koi8-r;
access_log logs/host.access.log main;
location / {
root /app/public/www;
index index.html index.htm index.php;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ .*\.(php|php5)?$ {
#fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1d;
}
}
server {
listen 80;
server_name admin.leizhenfang.com;
root /app/public/www;
access_log logs/host.access.log main;
auth_basic "Restricted";
auth_basic_user_file webadmin.pass;
location / {
root /app/public/www;
index index.html index.htm index.php;
}
location ~ .*\.(php|php5)?$ {
#fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
server {
listen 80;
server_name status.leizhenfang.com;
location / {
stub_status on;
access_log off;
}
}
}
其中webadmin.pass是在conf目录下的htpasswd生成的文件 -
php-fpm配置
Posted on 十二月 19th, 2008 No comments<?xml version="1.0" ?>
<configuration>
All relative paths in this config are relative to php's install prefix
<section name="global_options">
Pid file
<value name="pid_file">/usr/local/logs/php-fpm.pid</value>
Error log file
<value name="error_log">/usr/local/logs/php-fpm.log</value>
Log level
<value name="log_level">notice</value>
When this amount of php processes exited with SIGSEGV or SIGBUS ...
<value name="emergency_restart_threshold">10</value>
... in a less than this interval of time, a graceful restart will be initiated.
Useful to work around accidental curruptions in accelerator's shared memory.
<value name="emergency_restart_interval">1m</value>
Time limit on waiting child's reaction on signals from master
<value name="process_control_timeout">5s</value>
Set to 'no' to debug fpm
<value name="daemonize">yes</value>
</section>
<workers>
<section name="pool">
Name of pool. Used in logs and stats.
<value name="name">default</value>
Address to accept fastcgi requests on.
Valid syntax is 'ip.ad.re.ss:port' or just 'port' or '/path/to/unix/socket'
<value name="listen_address">127.0.0.1:9000</value>
<value name="listen_options">
Set listen(2) backlog
<value name="backlog">-1</value>
Set permissions for unix socket, if one used.
In Linux read/write permissions must be set in order to allow connections from web server.
Many BSD-derrived systems allow connections regardless of permissions.
<value name="owner"></value>
<value name="group"></value>
<value name="mode">0666</value>
</value>
Additional php.ini defines, specific to this pool of workers.
<value name="php_defines">
<value name="sendmail_path">/usr/sbin/sendmail -t -i</value>
<value name="display_errors">1</value>
</value>
Unix user of processes
<value name="user">nobody</value>
Unix group of processes
<value name="group">nobody</value>
Process manager settings
<value name="pm">
Sets style of controling worker process count.
Valid values are 'static' and 'apache-like'
<value name="style">static</value>
Sets the limit on the number of simultaneous requests that will be served.
Equivalent to Apache MaxClients directive.
Equivalent to PHP_FCGI_CHILDREN environment in original php.fcgi
Used with any pm_style.
<value name="max_children">128</value>
Settings group for 'apache-like' pm style
<value name="apache_like">
Sets the number of server processes created on startup.
Used only when 'apache-like' pm_style is selected
<value name="StartServers">20</value>
Sets the desired minimum number of idle server processes.
Used only when 'apache-like' pm_style is selected
<value name="MinSpareServers">5</value>
Sets the desired maximum number of idle server processes.
Used only when 'apache-like' pm_style is selected
<value name="MaxSpareServers">35</value>
</value>
</value>
The timeout (in seconds) for serving a single request after which the worker process will be terminated
Should be used when 'max_execution_time' ini option does not stop script execution for some reason
'0s' means 'off'
<value name="request_terminate_timeout">0s</value>
The timeout (in seconds) for serving of single request after which a php backtrace will be dumped to slow.log file
'0s' means 'off'
<value name="request_slowlog_timeout">0s</value>
The log file for slow requests
<value name="slowlog">logs/slow.log</value>
Set open file desc rlimit
<value name="rlimit_files">51200</value>
Set max core size rlimit
<value name="rlimit_core">0</value>
Chroot to this directory at the start, absolute path
<value name="chroot"></value>
Chdir to this directory at the start, absolute path
<value name="chdir"></value>
Redirect workers' stdout and stderr into main error log.
If not set, they will be redirected to /dev/null, according to FastCGI specs
<value name="catch_workers_output">yes</value>
How much requests each process should execute before respawn.
Useful to work around memory leaks in 3rd party libraries.
For endless request processing please specify 0
Equivalent to PHP_FCGI_MAX_REQUESTS
<value name="max_requests">500</value>
Comma separated list of ipv4 addresses of FastCGI clients that allowed to connect.
Equivalent to FCGI_WEB_SERVER_ADDRS environment in original php.fcgi (5.2.2+)
Makes sense only with AF_INET listening socket.
<value name="allowed_clients">127.0.0.1</value>
Pass environment variables like LD_LIBRARY_PATH
All $VARIABLEs are taken from current environment
<value name="environment">
<value name="HOSTNAME">$HOSTNAME</value>
<value name="PATH">/usr/local/bin:/usr/bin:/bin</value>
<value name="TMP">/tmp</value>
<value name="TMPDIR">/tmp</value>
<value name="TEMP">/tmp</value>
<value name="OSTYPE">$OSTYPE</value>
<value name="MACHTYPE">$MACHTYPE</value>
<value name="MALLOC_CHECK_">2</value>
</value>
</section>
</workers>
</configuration>
如果内存较小,可以考虑使用以下修改:
将启动的php-cgi进程数由原来的128个改为5个:
<value name=”max_children”>5</value>
将TCP模式改为Unix Socket模式:<value name=”listen_address”>/tmp/php-cgi.sock</value>

