yum -y install wget --noplugins
wget freevps.us/downloads/nginx-centos-6.sh -O - | bash

注意安装完成后 php-fpm 默认跑在 apache 用户上。

安装完成后,如果你需要的 PHP 扩展未安装,可输入如下命令查询:

yum list | grep ^php*

找到了扩展的名字,就可以直接安装了:

# 以 php memcache 扩展为例
yum install -y php-pecl-memcached

此外还遇到的问题是 DOMDocument 找不到,直接 yum 安装 php-xml:

yum install -y php-xml

所有扩展 yum 安装完成后都需要重新启动 / 载入 php-fpm。
贴下内容来看看(非最新版本,请直接下载 .sh 文件):

#!/bin/bash

##################
# disable apache #
##################
service httpd stop 
chkconfig httpd off
service xinetd stop
chkconfig xinetd off
service saslauthd stop
chkconfig saslauthd off
service sendmail stop
chkconfig sendmail off
service postfix stop
chkconfig postfix off

#Optimize yum on OpenVZ
if [ -e "/proc/user_beancounters" ]
then
  sed -i 's/plugins=1/plugins=0/' /etc/yum.conf
fi

#remove all current PHP and MySQL, will reinstall later. Also, remove apache 
yum -y remove httpd php mysql rsyslog sendmail postfix

###################
# Add a few repos #
###################
# install the Atomic repo for php and nginx (may use epel for nginx depending on version)
wget -q -O - http://www.atomicorp.com/installers/atomic | sh

# RPMForge for nginx dependencies
rpm -Uvh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.i686.rpm

#EPEL for syslog-ng and nginx (may use atomic for nginx depending on version)
rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-5.noarch.rpm

################################
# Install PHP, NGINX and MySQL #
################################
#yum install GeoIP libGeoIP.so.1 --enablerepo=repoforge
yum -y install mysql-server php-fpm php-mysql php-gd nginx nano exim syslog-ng

#################
# install MySQL #
#################
#yum -y install mysql-server
cat > /etc/my.cnf <<END
[mysqld]
default-storage-engine = myisam
key_buffer = 8M
query_cache_size = 8M
query_cache_limit = 4M
max_connections=25
thread_cache=1
skip-innodb 
query_cache_min_res_unit=0
tmp_table_size = 4M
max_heap_table_size = 4M
table_cache=256
concurrent_insert=2 
END
echo  Do not worry if you see a error stopping MySQL or NGINX
/etc/init.d/mysqld stop
/etc/init.d/mysqld start

####################
# Set up NGINX PHP #
####################
cat > /etc/nginx/php <<END
index index.php index.html index.htm;

location ~ \.php$ {

   include fastcgi_params;
    fastcgi_intercept_errors on;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
  try_files \$uri =404;
    fastcgi_pass 127.0.0.1:9000;
    error_page 404 /404page.html; #makes nginx return it's default 404 
#	page instead of a blank page

} 
END

cat > /etc/nginx/nginx.conf <<END
user              nginx nginx;
worker_processes  2;

error_log         logs/error.log;

pid               logs/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    client_max_body_size 64M;
    sendfile        on;
    tcp_nopush      on;

    keepalive_timeout  3;

    gzip  on;
    gzip_comp_level 2;
    gzip_proxied any;
    gzip_types      text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;

    server_tokens off;

    include /etc/nginx/conf.d/*;
} 
END
rm /etc/nginx/conf.d/*
cat > /etc/nginx/conf.d/default.conf <<END
server {
    listen 80 default;
    server_name _;
    root /var/www/html;
    include php;

  } 
END
mkdir /usr/share/nginx/logs/
service nginx restart
chkconfig nginx on
chkconfig mysqld on

cat > /etc/php-fpm.d/www.conf <<END
; Start a new pool named 'www'.
[www]

; The address on which to accept FastCGI requests.
; Valid syntaxes are:
;   'ip.add.re.ss:port'    - to listen on a TCP socket to a specific address on
;                            a specific port;
;   'port'                 - to listen on a TCP socket to all addresses on a
;                            specific port;
;   '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = 127.0.0.1:9000

; Set listen(2) backlog. A value of '-1' means unlimited.
; Default Value: -1
;listen.backlog = -1

; List of ipv4 addresses of FastCGI clients which are allowed to connect.
; Equivalent to the FCGI_WEB_SERVER_ADDRS environment variable in the original
; PHP FCGI (5.2.2+). Makes sense only with a tcp listening socket. Each address
; must be separated by a comma. If this value is left blank, connections will be
; accepted from any ip address.
; Default Value: any
listen.allowed_clients = 127.0.0.1

; Set permissions for unix socket, if one is used. In Linux, read/write
; permissions must be set in order to allow connections from a web server. Many
; BSD-derived systems allow connections regardless of permissions. 
; Default Values: user and group are set as the running user
;                 mode is set to 0666
;listen.owner = nobody
;listen.group = nobody
;listen.mode = 0666

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
; RPM: apache Choosed to be able to access some dir as httpd
user = apache
; RPM: Keep a group allowed to write in log dir.
group = apache

; Choose how the process manager will control the number of child processes.
; Possible Values:
;   static  - a fixed number (pm.max_children) of child processes;
;   dynamic - the number of child processes are set dynamically based on the
;             following directives:
;             pm.max_children      - the maximum number of children that can
;                                    be alive at the same time.
;             pm.start_servers     - the number of children created on startup.
;             pm.min_spare_servers - the minimum number of children in 'idle'
;                                    state (waiting to process). If the number
;                                    of 'idle' processes is less than this
;                                    number then some children will be created.
;             pm.max_spare_servers - the maximum number of children in 'idle'
;                                    state (waiting to process). If the number
;                                    of 'idle' processes is greater than this
;                                    number then some children will be killed.
; Note: This value is mandatory.
pm = dynamic

; The number of child processes to be created when pm is set to 'static' and the
; maximum number of child processes to be created when pm is set to 'dynamic'.
; This value sets the limit on the number of simultaneous requests that will be
; served. Equivalent to the ApacheMaxClients directive with mpm_prefork.
; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP
; CGI.
; Note: Used when pm is set to either 'static' or 'dynamic'
; Note: This value is mandatory.
pm.max_children = 5

; The number of child processes created on startup.
; Note: Used only when pm is set to 'dynamic'
; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2
pm.start_servers = 1

; The desired minimum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.min_spare_servers = 1

; The desired maximum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.max_spare_servers = 3

; The number of requests each child process should execute before respawning.
; This can be useful to work around memory leaks in 3rd party libraries. For
; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS.
; Default Value: 0
pm.max_requests = 500

; The URI to view the FPM status page. If this value is not set, no URI will be
; recognized as a status page. By default, the status page shows the following
; information:
;   accepted conn    - the number of request accepted by the pool;
;   pool             - the name of the pool;
;   process manager  - static or dynamic;
;   idle processes   - the number of idle processes;
;   active processes - the number of active processes;
;   total processes  - the number of idle + active processes.
; The values of 'idle processes', 'active processes' and 'total processes' are
; updated each second. The value of 'accepted conn' is updated in real time.
; Example output:
;   accepted conn:   12073
;   pool:             www
;   process manager:  static
;   idle processes:   35
;   active processes: 65
;   total processes:  100
; By default the status page output is formatted as text/plain. Passing either
; 'html' or 'json' as a query string will return the corresponding output
; syntax. Example:
;   http://www.foo.bar/status
;   http://www.foo.bar/status?json
;   http://www.foo.bar/status?html
; Note: The value must start with a leading slash (/). The value can be
;       anything, but it may not be a good idea to use the .php extension or it
;       may conflict with a real PHP file.
; Default Value: not set 
;pm.status_path = /status

; The ping URI to call the monitoring page of FPM. If this value is not set, no
; URI will be recognized as a ping page. This could be used to test from outside
; that FPM is alive and responding, or to
; - create a graph of FPM availability (rrd or such);
; - remove a server from a group if it is not responding (load balancing);
; - trigger alerts for the operating team (24/7).
; Note: The value must start with a leading slash (/). The value can be
;       anything, but it may not be a good idea to use the .php extension or it
;       may conflict with a real PHP file.
; Default Value: not set
;ping.path = /ping

; This directive may be used to customize the response of a ping request. The
; response is formatted as text/plain with a 200 response code.
; Default Value: pong
;ping.response = pong

; The timeout for serving a single request after which the worker process will
; be killed. This option should be used when the 'max_execution_time' ini option
; does not stop script execution for some reason. A value of '0' means 'off'.
; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
; Default Value: 0
;request_terminate_timeout = 0

; The timeout for serving a single request after which a PHP backtrace will be
; dumped to the 'slowlog' file. A value of '0s' means 'off'.
; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
; Default Value: 0
;request_slowlog_timeout = 0

; The log file for slow requests
; Default Value: /var/log/php-fpm.log.slow
;slowlog = /var/log/php-fpm.log.slow

; Set open file descriptor rlimit.
; Default Value: system defined value
;rlimit_files = 1024

; Set max core size rlimit.
; Possible Values: 'unlimited' or an integer greater or equal to 0
; Default Value: system defined value
;rlimit_core = 0

; Chroot to this directory at the start. This value must be defined as an
; absolute path. When this value is not set, chroot is not used.
; Note: chrooting is a great security feature and should be used whenever 
;       possible. However, all PHP paths will be relative to the chroot
;       (error_log, sessions.save_path, ...).
; Default Value: not set
;chroot = 

; Chdir to this directory at the start. This value must be an absolute path.
; Default Value: current directory or / when chroot
;chdir = /var/www

; Redirect worker stdout and stderr into main error log. If not set, stdout and
; stderr will be redirected to /dev/null according to FastCGI specs.
; Default Value: no
;catch_workers_output = yes

; Pass environment variables like LD_LIBRARY_PATH. All $VARIABLEs are taken from
; the current environment.
; Default Value: clean env
;env[HOSTNAME] = $HOSTNAME
;env[PATH] = /usr/local/bin:/usr/bin:/bin
;env[TMP] = /tmp
;env[TMPDIR] = /tmp
;env[TEMP] = /tmp

; Additional php.ini defines, specific to this pool of workers. These settings
; overwrite the values previously defined in the php.ini. The directives are the
; same as the PHP SAPI:
;   php_value/php_flag             - you can set classic ini defines which can
;                                    be overwritten from PHP call 'ini_set'. 
;   php_admin_value/php_admin_flag - these directives won't be overwritten by
;                                     PHP call 'ini_set'
; For php_*flag, valid values are on, off, 1, 0, true, false, yes or no.

; Defining 'extension' will load the corresponding shared extension from
; extension_dir. Defining 'disable_functions' or 'disable_classes' will not
; overwrite previously defined php.ini values, but will append the new value
; instead.

; Default Value: nothing is defined by default except the values in php.ini and
;                specified at startup with the -d argument
;php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f www@my.domain.com
;php_flag[display_errors] = off
php_admin_value[error_log] = /var/log/php-fpm/www-error.log
php_admin_flag[log_errors] = on
;php_admin_value[memory_limit] = 32M
php_admin_value[upload_max_filesize] = 32M
END

mkdir /var/www
mkdir /var/www/html/
useradd apache
service php-fpm start
chkconfig php-fpm on
iptables -I INPUT -p tcp --dport 80 -j ACCEPT
service iptables save

wget freevps.us/downloads/setup-vhost.sh -O /bin/setup-vhost
chmod 755 /bin/setup-vhost
echo "alias nano='nano -w'" >> ~/.bashrc
clear
echo Installation done.
echo to create a vhost, run
echo setup-vhost example.com
echo do not include the www. subdomain.

转:http://blog.csdn.net/xymyeah/article/details/6939544

一、一般来说nginx 配置文件中对优化比较有作用的为以下几项:

1. worker_processes 8;

nginx 进程数,建议按照cpu 数目来指定,一般为它的倍数 (如,2个四核的cpu计为8)。

2. worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;

为每个进程分配cpu,上例中将8 个进程分配到8 个cpu,当然可以写多个,或者将一
个进程分配到多个cpu。

3. worker_rlimit_nofile 65535;

这个指令是指当一个nginx 进程打开的最多文件描述符数目,理论值应该是最多打开文
件数(ulimit -n)与nginx 进程数相除,但是nginx 分配请求并不是那么均匀,所以最好与ulimit -n 的值保持一致。

现在在linux 2.6内核下开启文件打开数为65535,worker_rlimit_nofile就相应应该填写65535。

这是因为nginx调度时分配请求到进程并不是那么的均衡,所以假如填写10240,总并发量达到3-4万时就有进程可能超过10240了,这时会返回502错误。

查看linux系统文件描述符的方法:

[root@web001 ~]# sysctl -a | grep fs.file

fs.file-max = 789972

fs.file-nr = 510 0 789972

4. use epoll;
使用epoll 的I/O 模型

(

补充说明:

与apache相类,nginx针对不同的操作系统,有不同的事件模型

A)标准事件模型
Select、poll属于标准事件模型,如果当前系统不存在更有效的方法,nginx会选择select或poll
B)高效事件模型
Kqueue:使用于 FreeBSD 4.1+, OpenBSD 2.9+, NetBSD 2.0 和 MacOS X. 使用双处理器的MacOS X系统使用kqueue可能会造成内核崩溃。
Epoll: 使用于Linux内核2.6版本及以后的系统。

/dev/poll:使用于 Solaris 7 11/99+, HP/UX 11.22+ (eventport), IRIX 6.5.15+ 和 Tru64 UNIX 5.1A+。

Eventport:使用于 Solaris 10. 为了防止出现内核崩溃的问题, 有必要安装安全补丁。

)

5. worker_connections 65535;

每个进程允许的最多连接数, 理论上每台nginx 服务器的最大连接数为worker_processes*worker_connections。

6. keepalive_timeout 60;

keepalive 超时时间。

7. client_header_buffer_size 4k;

客户端请求头部的缓冲区大小,这个可以根据你的系统分页大小来设置,一般一个请求头的大小不会超过1k,不过由于一般系统分页都要大于1k,所以这里设置为分页大小。

分页大小可以用命令getconf PAGESIZE 取得。

[root@web001 ~]# getconf PAGESIZE

4096

但也有client_header_buffer_size超过4k的情况,但是client_header_buffer_size该值必须设置为“系统分页大小”的整倍数。

8. open_file_cache max=65535 inactive=60s;

这个将为打开文件指定缓存,默认是没有启用的,max 指定缓存数量,建议和打开文件数一致,inactive 是指经过多长时间文件没被请求后删除缓存。

9. open_file_cache_valid 80s;

这个是指多长时间检查一次缓存的有效信息。

10. open_file_cache_min_uses 1;

open_file_cache 指令中的inactive 参数时间内文件的最少使用次数,如果超过这个数字,文件描述符一直是在缓存中打开的,如上例,如果有一个文件在inactive 时间内一次没被使用,它将被移除。

二、关于内核参数的优化:

net.ipv4.tcp_max_tw_buckets = 6000

timewait 的数量,默认是180000。

net.ipv4.ip_local_port_range = 1024 65000

允许系统打开的端口范围。

net.ipv4.tcp_tw_recycle = 1

启用timewait 快速回收。

net.ipv4.tcp_tw_reuse = 1

开启重用。允许将TIME-WAIT sockets 重新用于新的TCP 连接。

net.ipv4.tcp_syncookies = 1

开启SYN Cookies,当出现SYN 等待队列溢出时,启用cookies 来处理。

net.core.somaxconn = 262144

web 应用中listen 函数的backlog 默认会给我们内核参数的net.core.somaxconn 限制到128,而nginx 定义的NGX_LISTEN_BACKLOG 默认为511,所以有必要调整这个值。

net.core.netdev_max_backlog = 262144

每个网络接口接收数据包的速率比内核处理这些包的速率快时,允许送到队列的数据包的最大数目。

net.ipv4.tcp_max_orphans = 262144

系统中最多有多少个TCP 套接字不被关联到任何一个用户文件句柄上。如果超过这个数字,孤儿连接将即刻被复位并打印出警告信息。这个限制仅仅是为了防止简单的DoS 攻击,不能过分依靠它或者人为地减小这个值,更应该增加这个值(如果增加了内存之后)。

net.ipv4.tcp_max_syn_backlog = 262144

记录的那些尚未收到客户端确认信息的连接请求的最大值。对于有128M 内存的系统而言,缺省值是1024,小内存的系统则是128。

net.ipv4.tcp_timestamps = 0

时间戳可以避免序列号的卷绕。一个1Gbps 的链路肯定会遇到以前用过的序列号。时间戳能够让内核接受这种“异常”的数据包。这里需要将其关掉。

net.ipv4.tcp_synack_retries = 1

为了打开对端的连接,内核需要发送一个SYN 并附带一个回应前面一个SYN 的ACK。也就是所谓三次握手中的第二次握手。这个设置决定了内核放弃连接之前发送SYN+ACK 包的数量。

net.ipv4.tcp_syn_retries = 1

在内核放弃建立连接之前发送SYN 包的数量。

net.ipv4.tcp_fin_timeout = 1

如果套接字由本端要求关闭,这个参数决定了它保持在FIN-WAIT-2 状态的时间。对端可以出错并永远不关闭连接,甚至意外当机。缺省值是60 秒。2.2 内核的通常值是180 秒,3你可以按这个设置,但要记住的是,即使你的机器是一个轻载的WEB 服务器,也有因为大量的死套接字而内存溢出的风险,FIN- WAIT-2 的危险性比FIN-WAIT-1 要小,因为它最多只能吃掉1.5K 内存,但是它们的生存期长些。

net.ipv4.tcp_keepalive_time = 30

当keepalive 起用的时候,TCP 发送keepalive 消息的频度。缺省是2 小时。

三、下面贴一个完整的内核优化设置:

vi /etc/sysctl.conf CentOS5.5中可以将所有内容清空直接替换为如下内容:

net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
net.ipv4.tcp_max_tw_buckets = 6000
net.ipv4.tcp_sack = 1
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_rmem = 4096 87380 4194304
net.ipv4.tcp_wmem = 4096 16384 4194304
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.core.netdev_max_backlog = 262144
net.core.somaxconn = 262144
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_keepalive_time = 30
net.ipv4.ip_local_port_range = 1024 65000

使配置立即生效可使用如下命令:
/sbin/sysctl -p

四、下面是关于系统连接数的优化

linux 默认值 open files 和 max user processes 为 1024

#ulimit -n

1024

#ulimit –u

1024

问题描述: 说明 server 只允许同时打开 1024 个文件,处理 1024 个用户进程

使用ulimit -a 可以查看当前系统的所有限制值,使用ulimit -n 可以查看当前的最大打开文件数。

新装的linux 默认只有1024 ,当作负载较大的服务器时,很容易遇到error: too many open files 。因此,需要将其改大。

解决方法:

使用 ulimit –n 65535 可即时修改,但重启后就无效了。(注ulimit -SHn 65535 等效 ulimit -n 65535 ,-S 指soft ,-H 指hard)

有如下三种修改方式:

1. 在/etc/rc.local 中增加一行 ulimit -SHn 65535
2. 在/etc/profile 中增加一行 ulimit -SHn 65535
3. 在/etc/security/limits.conf 最后增加:

* soft nofile 65535
* hard nofile 65535
* soft nproc 65535
* hard nproc 65535

具体使用哪种,在 CentOS 中使用第1 种方式无效果,使用第3 种方式有效果,而在Debian 中使用第2 种有效果

# ulimit -n

65535

# ulimit -u

65535

备注:ulimit 命令本身就有分软硬设置,加-H 就是硬,加-S 就是软默认显示的是软限制

soft 限制指的是当前系统生效的设置值。 hard 限制值可以被普通用户降低。但是不能增加。 soft 限制不能设置的比 hard 限制更高。 只有 root 用户才能够增加 hard 限制值。

五、下面是一个简单的nginx 配置文件:

user www www;
worker_processes 8;
worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000
01000000;
error_log /www/log/nginx_error.log crit;
pid /usr/local/nginx/nginx.pid;
worker_rlimit_nofile 204800;
events
{
use epoll;
worker_connections 204800;
}
http
{
include mime.types;
default_type application/octet-stream;
charset utf-8;
server_names_hash_bucket_size 128;
client_header_buffer_size 2k;
large_client_header_buffers 4 4k;
client_max_body_size 8m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
fastcgi_cache_path /usr/local/nginx/fastcgi_cache levels=1:2
keys_zone=TEST:10m
inactive=5m;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 4k;
fastcgi_buffers 8 4k;
fastcgi_busy_buffers_size 8k;
fastcgi_temp_file_write_size 8k;
fastcgi_cache TEST;
fastcgi_cache_valid 200 302 1h;
fastcgi_cache_valid 301 1d;
fastcgi_cache_valid any 1m;
fastcgi_cache_min_uses 1;
fastcgi_cache_use_stale error timeout invalid_header http_500;
open_file_cache max=204800 inactive=20s;
open_file_cache_min_uses 1;
open_file_cache_valid 30s;
tcp_nodelay on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
server
{
listen 8080;
server_name backup.aiju.com;
index index.php index.htm;
root /www/html/;
location /status
{
stub_status on;
}
location ~ .*\.(php|php5)?$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$
{
expires 30d;
}
log_format access ‘$remote_addr — $remote_user [$time_local] “$request” ‘
‘$status $body_bytes_sent “$http_referer” ‘
‘”$http_user_agent” $http_x_forwarded_for’;
access_log /www/log/access.log access;
}
}

六、关于FastCGI 的几个指令:

fastcgi_cache_path /usr/local/nginx/fastcgi_cache levels=1:2 keys_zone=TEST:10minactive=5m;

这个指令为FastCGI 缓存指定一个路径,目录结构等级,关键字区域存储时间和非活动删除时间。

fastcgi_connect_timeout 300;

指定连接到后端FastCGI 的超时时间。

fastcgi_send_timeout 300;

向FastCGI 传送请求的超时时间,这个值是指已经完成两次握手后向FastCGI 传送请求的超时时间。

fastcgi_read_timeout 300;

接收FastCGI 应答的超时时间,这个值是指已经完成两次握手后接收FastCGI 应答的超时时间。

fastcgi_buffer_size 4k;

指定读取FastCGI 应答第一部分需要用多大的缓冲区,一般第一部分应答不会超过1k,由于页面大小为4k,所以这里设置为4k。

fastcgi_buffers 8 4k;

指定本地需要用多少和多大的缓冲区来缓冲FastCGI 的应答。

fastcgi_busy_buffers_size 8k;

这个指令我也不知道是做什么用,只知道默认值是fastcgi_buffers 的两倍。

fastcgi_temp_file_write_size 8k;

在写入fastcgi_temp_path 时将用多大的数据块,默认值是fastcgi_buffers 的两倍。

fastcgi_cache TEST

开启FastCGI 缓存并且为其制定一个名称。个人感觉开启缓存非常有用,可以有效降低CPU 负载,并且防止502 错误。

fastcgi_cache_valid 200 302 1h;
fastcgi_cache_valid 301 1d;
fastcgi_cache_valid any 1m;

为指定的应答代码指定缓存时间,如上例中将200,302 应答缓存一小时,301 应答缓存1 天,其他为1 分钟。

fastcgi_cache_min_uses 1;

缓存在fastcgi_cache_path 指令inactive 参数值时间内的最少使用次数,如上例,如果在5 分钟内某文件1 次也没有被使用,那么这个文件将被移除。

fastcgi_cache_use_stale error timeout invalid_header http_500;

不知道这个参数的作用,猜想应该是让nginx 知道哪些类型的缓存是没用的。以上为nginx 中FastCGI 相关参数,另外,FastCGI 自身也有一些配置需要进行优化,如果你使用php-fpm 来管理FastCGI,可以修改配置文件中的以下值:

60

同时处理的并发请求数,即它将开启最多60 个子线程来处理并发连接。

102400

最多打开文件数。

204800

每个进程在重置之前能够执行的最多请求数。

转载:http://club.alimama.com/read-htm-tid-1221587-fpage-2.html

下面的代码只是为了讲解才这样列出来的,不一定全要用上,要根据自己网站的情况.
如下面5,6两行就要根据自己网站情况进行定义的

********************************************************

1、<!--页面注解-->
2、<html>
3、<head>
4、<title>页面标题</title>
5、<meta http-equiv=Content-Language content=zh-cn>
6、<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
7、<meta name="keywords" content="关键词">
8、<meta name="description" content="网站描述">
9、<link href="inc/css.css" type="text/css" rel="stylesheet">
10、</head>
11、<body>
12、<div>
13、<h1>页面内容标题</h1>
14、<h2>页面相关性标题</h2>
15、<h3>标题系列</h3>
16、<h4>标题系列</h4>
17、<h5>标题系列</h5>
18、<h6>标题系列</h6>
19、<img data-original="xxx.jpg" alt="图片说明">
20、<a href="/" title="链接说明">链接词</a>
21、<strong>重点关键词强调</strong>
22、<b>关键词强调</b><u>关键词强调</u><i>关键词强调</i>
23、</div>
25、<div>
26、版权部分关键词强调
27、</div>
28、</body>
29、</html>

********************************************************

注:在<body>..</body>标签区中的罗列,都是一些基础的HTML标签,这些标签出现的次序是可以变化的。

下面来给大家详细解答一下。

第1行的<!--页面注解-->
这个标签是用来做HTML代码注解的,很多站在这里会写上关键词,这种形式的注解在浏览器中是不会显示的,而搜索引擎可以读到。所以这个标签有的时候会成为作弊的一种形式,不要过多的用这种标签到来注明你的关键词,否则如果搜索引擎认为你是作弊的话,就惨了。

第4行<title>页面标题</title>。这是相当重要的!
这里字字值千金!对于做百度SEO的朋友,一定要记得这个标签可能是你是否真正能够做到排名靠前的重点,而且这个重点绝对不容忽视。标题主要注意你的用词,如果你做垃圾站,堆关键词也无所谓,如果你要做正规站点,请你正确对待,写得标准一点,不要堆关键字,保持你的主要词在这里出现三次就行,太多对你没有好处,对排名也不会有好处。GG并不喜欢太长的标题,百度也偶尔提到只希望在标题的前20个字里出现你的关键词。明确这些以后,还要注意的是,你的主要关键词应该在标题里越靠前越好!

第7行<meta name="keywords" content="关键词">这个的用途现在权重越来越低,但是再低都是有权重的,只要认真对待,这里的词是有效果的。这里注意两点:
第一、大部分人都会选择在这里写关键词不会超过三个,有的人直接只写一个,这是有好处的,每一处标签都有权重,你强调的内容越少,那么它的权重会相对更高的,所以不要写太多,否则不如不写,而让搜索引擎自己去判断你的页面关键词。
第二、几乎所有的SEO专业人员都会跟你说尽量在每一个页面写不同的关键词,避免被认为是重复页面的危险。

第8行<meta name="description" content="网站描述">这个是主要为了在搜索结果里出现的索引结果的,索引结果就是在百度搜索你的站的时候标题下面的摘要内容。这是一个页面的导读,用来说明网页的主要内容,当然现在的权重不高,跟keywords标签一样,不太受重视。而且现在由于搜索引擎机器人的越来越智能化,基本上已经实现整个页面的摘要内容随意出现它的索引结果里了,搜索引擎会根据你搜索的内容不同显示不同的索引。你如果要写description,就认真去写,很多人是用这里来控制搜索引擎的索引显示的,因为网站描述写得越具体,就越有可能在索引的时候出现这个标签中的内容。

第13行<h1>页面内容标题</h1>这个标签是一个页面最重要的标签,也是搜索引擎定位这个页面的主要依据,如果你的<h1>标签里没有出现你的页面关键字,那真是的一种很大的损失,这里的权重相对于其它的在<body>区的标签来说更加重要。在HTML代码中,它的重要性仅次于<title>。很多人放弃写这个标签,对于搜索引擎是很不友好的,你可以不出现其它的强调关键词的标签,但是这个标签一定要出现,这是告诉搜索引擎你的页面用一句话应该如何表达,如果这一行字都没有,再智能化的机器人可能都会以你的<title>来决定是否用来作为一个词的排名,很多时候一个网站的页面标题都是完全一样的,因为他们程序的原因,但是如果你没有办法修改title,已经损失很大了,而如果你的页面这个<h1>标签也没有出现的话,我不知道搜索引擎会怎么样去理解一个页面,对于SEO来说,那真很糟糕的一件事情。所以,认真对待你的页面<h1>,这是很重要的,要强调的是,这个标签一个页面不要出现太多,一次就行了,道理很简单,太多会让别人无法确定你页面中哪一个才是最重要的,无法确定重点跟没有这个标签我觉得没有太大的分别。所以,最好只出现1次,以达到明确说明的目的。

第14行<h2>页面相关性标题</h2>这个标签与<h1>是一样和道理,但是权重相对来说较低,如果你的页面没有<h1>,那么这个标签对于页面来说基本上就相当于<h1>的重要性了。这里面你包含的是长尾关键词相关的内容,比如你的页面做几个关键词,主词应该出现在<h1>里,那么其它的词以及你想发展的词就可以出现在<h2>里,这样来说是一种合理的安排。
而<h3>~<h6>这些标签,重要性是依次递减的,在一个页面的权重越来越低。

第19行<img data-original="xxx.jpg" alt="图片说明">我想这个标签很多人都知道,它的作用很明确,就是指定一张图片的说明文字,让搜索引擎知道这张图片是关于什么的。比如你的图片是"刘亦菲",那么你的alt="图片说明"中的"图片说明"就应该是与"刘亦菲"相关的词或者句子。这样写当然也有利于你在图片搜索的结果里显示排名更前面一点,不过现在百度基本上是以页面标题作为一张图片排名的要素,当然,你的alt标记做得好,将会增加你的图片匹配度。关于图片说明的研究,以后我也许会写一篇分析性的文章,因为有<a>链接的图片里,还会有一个title标签,title与alt这两个谁重要,是有必要研究一下的。

第20行<a href="/" title="链接说明">链接词</a>这是链接说明,同时也是一个页面链接的SEO重点,这里的"链接词"相当的重要,如果你跟别人交换链接,你这个词的写法是起着外链好坏与否的决定性因素的。"链接词"建议你最好写成自己的关键词,如果觉得实在不行或者怎么样,你一定要在"链接说明"里出现你的关键词。否则对于排名,你的链接做得没有太大的好处。这在SEO专业术语里还有一种叫法,叫做"google炸弹",就是用很多站点,同时做链接到一个网站,然后所有的"链接词"都写一个词-"刘亦菲",不久以后google就会将这个站当做"刘亦菲"这个词最权威的站点,即使被那些站点链接的这个页面没有任何与"刘亦菲"相关的内容,这个网站在"刘亦菲"这个词的排名情况也会很好。不过google已经调整了算法,但是这样做链接肯定是有用的,一定要认真对待你的链接。还有一个重点,就是对方的链接,如果是JS调用的,你就别想在他那里得到任何权重,因为搜索引擎不会去读取JS里的内容,所以,建议大家好好做链接,不要做了链接你的站却跟没做一样。像百度空间的友情链接就是JS文件调用的,所以百度空间里的友情链接你是没有权重的。具体可以查看HTML代码,正常情况下一个页面你找不到你的网站地址在<a>..</a>标签内出现,基本上这就是属于无效链接。

第21行<strong>重点关键词强调</strong>这个标签基实重要性仅次于<h1>,很多人都这样跟我讲,我也基本上认同。很确定的是它比<b>、<u>、<i>等标签要权重高。所以如果你的页面有很重要的词,而你想强调它,首先选这个<strong>标签吧,接下来相对不重要的词强调请你选<b>、<u>、<i>等标签。当然,不要用得太多了,用得太多没有重点就等于没有用了。

第26行版权部分关键词强调
我为什么要写这个?因为这个权重越来越高了,在底部版权部分,及很接近版权部分出现关键词,是一种手法。在这里强调你的关键词,是让你的关键词布局更加合理,而不是头部出现关键词,中部强调很多次,而底部却没有什么相关联的内容,这个词在这个页面是否值得怀疑呢?

squid3.0 反向代理 apache2+squid3

我使用的环境CentOS5.5 yum的apache2+PHP5+squid,目前网站已配置成功。

一.APACHE配置
apache(81端口)+squid(80端口)(apache和squid跑在同一个机器上面 要实现反向代理 )我将我的外网域名用abc.com代替了

apache简单配置如下:
Listen 81
NameVirtualHost *
<VirtualHost *>
<Directory "/usr/local/www/">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
Satisfy all
</Directory>
ServerName    www.abc.com
ServerAdmin webadmin@abc.com
DocumentRoot "/usr/local/www/"
DirectoryIndex index.jsp
#    ErrorLog "/usr/local/apache/logs/abc-error_log"
#    SetEnvIf Remote_Addr "::1" dontlog
#    CustomLog "/usr/local/apache/logs/abc-access_log" combined env=!dontlog
</VirtualHost>

此时可以通过lsof -i:81查看谁占用81端口

二.SQUID配置
安装    rpm -ivh squid.3.x.rpm

配置    vi /etc/squid/squid.conf

#change for hugwww
visible_hostname www.151051.com

http_port 80 vhost vport

cache_peer 127.0.0.1 parent 81 0 no-query originserver

cache_peer_domain 127.0.0.1 www.151051.com

acl all data-original all

http_access allow all

cache_dir ufs /var/spool/squid 100 16 256

access_log /var/log/squid/access.log squid

cache_log /var/log/squid/cache.log

acl QueryString url_regex \.php?

no_cache deny QueryString

maximum_object_size 320010 KB

maximum_object_size_in_memory 100 KB

dns_nameservers 192.168.0.100

cache_mgr gaojinbo@dayang.com

#/usr/local/squid/sbin/squid -k parse
可以根据这个测试命令用来验证squid.conf的语法和配置(下面是OK的如果不OK会有相应的提示根据提示来修改配置文件)
2008/03/19 15:29:48| Processing Configuration File: /etc/squid.conf (depth 0)

#squid -z
用来Creating Swap Directories

还有测试命令如:squid -CNd1

[root@www ~]# cat /var/log/squid/access.log |grep TCP_MEM_HIT
该指令可以看到在squid运行过程中,有那些文件被squid缓存到内存中,并返回给访问用户

[root@www ~]# cat /var/log/squid/access.log |grep TCP_HIT
该指令可以看到在squid运行过程中,有那些文件被squid缓存到cache目录中,并返回给访问用户

[root@www ~]# cat /var/log/squid/access.log  |grep TCP_MISS
该指令可以看到在squid运行过程中,有那些文件没有被squid缓存,而是现重原始服务器获取并返回给访问用户

可以查看下命中率及其他相关信息
#squidclient -p 80 -h localhost mgr:info

三.配置客户端访问

1.修改HOSTS文件,将svr-ekp.broad-ocean.com的地址设置为192.168.0.193

2.修改DNS记录,将svr-ekp.broad-ocean.com的地址设置为192.168.0.193

3.浏览器访问svr-ekp.broad-ocean.com

注:第一步骤可省略,使用现在WEB服务器.

引用:http://genmicha.cn/chinese-troditional-simplified.htm

前几天浏览来源访问,发现有一位使用台湾Google的朋友,搜索到本blog,而且使用Google的在线简繁翻译的功能,但是效果不好。所以搜索了一下WordPress有没有相关的组件,就发现了下面这个。现在已经加到博客的右上角,可以简繁切换了。

-------------------------------------------------------------------------

大家基本上都是用中文写博客,我们也知道国内用的是简体中文,而港台澳和其他海外的华人用的是正体中文,也就是我们所说的繁体字。严格地说简体中文是繁体中文的阉割版,因为它是在繁体中文的基础上简化而来的。细心一点分析我们的统计就会发现,我们的读者不仅仅限于国内朋友,还有很多来自港台澳和国外的华人朋友也通过各种渠道来到我们的博客。简体字经过几十年的发展,已经深入到国内的每一个行业。但是很明显,简体字对于这些朋友来说很陌生,比较形象的说法是“缺胳膊少腿”。

上网的时候我们会发现很多网站都有繁体版本,通过导航栏上的一个按钮就可以把网页上的文字从简体中文变成繁体中文。很多主机商也提供类似于“简繁通”之类的产品,当然,是需要收费的。那么,怎么让我们的博客不用花钱也能支持简繁转换呢?

我们看到国内的很多博客用户都在自己的主页上添加了Google的翻译挂件,通过简单的设置让Google来为我们把网页从简体中文翻译成繁体中文或英语。而我介绍的这个简繁转换,是通过js的方式实现的。下面我就以WordPress为例说明一下:

前几天看到迅雷动漫主页上的幻灯片很有趣,抓下来研究一下。
全部代码下载
如有不妥请告知。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<HTML xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>动漫频道 - 迅雷看看</TITLE>
<META content="text/html; charset=utf-8" http-equiv=Content-Type>
<style>
* {
PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; PADDING-TOP: 0px
}
HTML {
BACKGROUND: #ffffff
}
BODY {
FONT: 12px/20px Arial, Verdana, Lucida, Helvetica, simsun, sans-serif; COLOR: #313131
}
A {
COLOR: #016a9f; TEXT-DECORATION: none
}
A:hover {
TEXT-DECORATION: underline
}
img {border:0px;}
.kk-catalog .rbgx .content {
HEIGHT: 363px
}
.kk-catalog .kanguo .content {
HEIGHT: 363px
}
.kk-catalog .qqdy .content {
HEIGHT: 310px
}
.kk-catalog .rank .content {
HEIGHT: 310px
}
.kk-index .flash-box {
PADDING-BOTTOM: 5px; PADDING-LEFT: 9px; WIDTH: 450px; PADDING-RIGHT: 9px; MARGIN-BOTTOM: 8px; BACKGROUND: url(../img/flashBg.png) no-repeat 0px 0px; HEIGHT: 251px; OVERFLOW: hidden; PADDING-TOP: 5px
}
.kk-index .flash-box H2 {
LINE-HEIGHT: 20px; WIDTH: 448px; MARGIN-BOTTOM: 1px; HEIGHT: 20px; COLOR: #193b5f; FONT-SIZE: 13px
}
.kk-index .flash-box .big-pic {
WIDTH: 366px; FLOAT: left; HEIGHT: 188px; OVERFLOW: hidden; MARGIN-RIGHT: 2px
}
.kk-index .flash-box .big-pic IMG {
BORDER-BOTTOM: #fff 1px solid; BORDER-LEFT: #fff 1px solid; WIDTH: 364px; DISPLAY: block; HEIGHT: 186px; BORDER-TOP: #fff 1px solid; BORDER-RIGHT: #fff 1px solid
}
.kk-index .flash-box .pic-list {
POSITION: relative; WIDTH: 81px; FLOAT: left; HEIGHT: 188px
}
.kk-index .flash-box .pic-list .pre {
POSITION: absolute; WIDTH: 81px; BACKGROUND: url(http://misc.web.xunlei.com/www_5_1/img/sprite.png) no-repeat; HEIGHT: 11px; TOP: 0px; LEFT: 0px
}
.kk-index .flash-box .pic-list .next {
POSITION: absolute; WIDTH: 81px; BACKGROUND: url(http://misc.web.xunlei.com/www_5_1/img/sprite.png) no-repeat; HEIGHT: 11px; TOP: 0px; LEFT: 0px
}

POP协议简介

本文简要说明了通过POP3协议收取邮件、MIME邮件的解码的原理;针对收取和MIME解码,提供了两个实用的PHP类,并提供了使用的样例。分为邮件收取、MIME解码两个部分。这里我们先向您介绍邮件的收取,解码部分会在以后的文章中为各位详细的介绍,敬请关注。

现在Internet上最大的应用应该是非Email莫属了,我们每天都习惯于每天通过Email进行交流,各大网站也几乎都推出了自己的基于WEB的免费邮件系统。在本文里,笔者将介绍一些Email实现的一些原理。同时我们假设你对于PHP的编程有一定的基础,对于TCP/IP协议也有一定的了解。

POP 协议简介
POP的全称是 Post Office Protoco ,即邮局协议,用于电子邮件的接收,现在常 用的是第三版 ,简称为 POP3。通过POP协议,客户机登录到服务器上后,可以对自己的邮件进行删除,或是下载到本地,下载后,电子邮件客户软件就可以在本地对邮件进行修改、删除等。另外一种用于接收信件的邮件是 IMAP 协议,现在发展很快,在本文中,我们暂不讨论。

POP服务器一般使用的是TCP的110号端口,如果你用的是Foxmail的话,在其收邮件的时候,你可以看到其信息提示窗口有这么一些命令:

“正在连接到 62.123.23.123:110";

"USER BOSS_CH";

"PASS..............";

下面让我们来看一段 与 POP3 服务器对话的实录:

telenet pop.china.com 110

+OK AIMC POP service (mail2.china.com) is ready.

USER boss_ch

+OK Please enter password for user .

PASS ******

+OK boss_ch has 1 messages (750 octets)

STAT

+OK 1 750

LIST

+OK 1 messages (750 octets)

1 750

RETR 1

+OK 750 octets

Received: from smtp2.ptt.js.cn([202.102.24.37]) by china.com(JetMail 2.5.3.0)

with SMTP id jm4839cc4227; Sat, 23 Sep 2000 05:31:21 -0000

Received: from chenjunqing ([61.155.120.6]) by smtp2.ptt.js.cn

(Netscape Messaging Server 4.15) with SMTP id G1BRHJ03.V07 for

; Sat, 23 Sep 2000 13:34:31 +0800

Date: Sat, 23 Sep 2000 13:34:18 +0800

From: =?ISO-8859-1?Q?=B3=C2=BF=A1=C7=E5?=

To: boss_ch@china.com

Subject: =?ISO-8859-1?Q?=D3=CA=BC=FE=CA=BE=C0=FD?=

X-mailer: FoxMail 3.1 [cn]

Mime-Version: 1.0

Content-Type: text/plain; charset="GB2312"

Content-Transfer-Encoding: 8bit

Message-ID:

您好!

这是一个邮件的小示例

QUIT

+OK Pop server at signing off.

以下对几个常用的POP3命令作一个简单的介绍 :

命令    参数    状态    描述

------------------------------------------

USER    username  认可    此命令与下面的pass命令若成功,将导致状态转换

PASS    password  认可

APOP    Name,Digest 认可    Digest是MD5消息摘要

------------------------------------------

STAT    None    处理    请求服务器发回关于邮箱的统计资料,如邮件总数和总字节数

UIDL    [Msg#]   处理    返回邮件的唯一标识符,POP3会话的每个标识符都将是唯一的

LIST    [Msg#]   处理    返回邮件数量和每个邮件的大小

RETR    [Msg#]   处理    返回由参数标识的邮件的全部文本

DELE    [Msg#]   处理    服务器将由参数标识的邮件标记为删除,由quit命令执行

RSET    None    处理    服务器将重置所有标记为删除的邮件,用于撤消DELE命令

TOP    [Msg#]    处理    服务器将返回由参数标识的邮件前n行内容,n必须是正整数

NOOP    None    处理    服务器返回一个肯定的响应,不做任何操作。

------------------------------------------

QUIT    None    更新 退出

用PHP实现POP3收取邮件的类

现在让我们来用PHP实现一个通过POP3协议收取信件的类吧,这个类中所用到的一些sock操作的函数,不另做特殊说明,请参考php的有关资料。通过这个实例,相信你也会和我一样,感觉到PHP中对于sock操作的灵活、方便和功能的强大。

首先,我们来说明一下这个类中需要用到的一些内部成员变量:(这些变量应该都是对外封闭的,可是由于php对类的成员变量没有private与publice之类的分别,只好就这么直接定义了。这是PHP的一个令人遗憾的地方。)

1.成员变量说明

class pop3
{

var $hostname=""; // POP主机名

var $port=110; // 主机的POP3端口,一般是110号端口

var $timeout=5;  // 连接主机的最大超时时间

var $connection=0; // 保存与主机的连接

var $state="DISCONNECTED"; // 保存当前的状态

var $debug=0;  // 做为标识,是否在调试状态,是的话,输出调试信息

var $err_str='';  // 如果出错,这里保存错误信息

var $err_no;   //如果出错,这里保存错误号码

var $resp; // 临时保存服务器的响应信息

var $apop; // 指示需要使用加密方式进行密码验证,一般服务器不需要

var $messages; // 邮件数

var $size; //各邮件的总大小

var $mail_list; // 一个数组,保存各个邮件的大小及其在邮件服务器上序号

var $head=array(); // 邮件头的内容,数组

var $body=array(); // 邮件体的内容,数组;

2.当然,这其中的有些变量,仅通过这样一个简单的说明并不能完全了解如何使用,下面我就逐个来说明这个类实现中的一些主要方法:
Function pop3($server="192.100.100.1",$port=110,$time_out=5)

{$this->hostname=$server;

$this->port=$port;

$this->timeout=$time_out;

return true;
}

熟悉面向对象编程的朋友一看就会知道,这是这个类的构造函数,在初始化这个类时,可以给出这几个最基本的参数:pop3服务器的地址,端口号,及连接服务器时的最大超时时间。一般来说,只需要给出POP3服务器的地址就行了。

Function open()
{
if($this->hostname=="")

{$this->err_str="无效的主机名!!";

return false;
}

if ($this->debug) echo "正在打开 $this->hostname,$this->port,&$err_no, &$err_str, $this->timeout
";

if (!$this->connection=fsockopen($this->hostname,$this->port,&$err_no, &$err_str, $this->timeout))
{

$this->err_str="连接到POP服务器失败,错误信息:".$err_str."错误号:".$err_no;

return false;

}
else
{
$this->getresp();

if($this->debug)

$this->outdebug($this->resp);

if (substr($this->resp,0,3)!="+OK")

{$this->err_str="服务器返回无效的信息:".$this->resp."请检查POP服务器是否正确";

return false;
}

$this->state="AUTHORIZATION";

return true;

}

}