寻觅生命中的那一片浅草......

每日存档 六月 24th, 2009

Discuz!在Nginx下的Rewrite

Discuz!在Nginx下的Rewrite
需要说明的是,下网上以前一直流传的Rewrite都是有误的。
下面的Rewrite中百分号前面多了个转移字符“\”,这在Apache中是需要的,而在Nginx中则是不需要的。
rewrite ^/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ /viewthread.php?tid=$1&extra=page\%3D$3&page=$2 last;
正确的应该是
rewrite ^/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ /viewthread.php?tid=$1&extra=page%3D$3&page=$2 last;
这个错误在基本上目前所有使用Nginx作为服务器,并且开启了Rewrite的网站上存在。包括Discuz!官方,目前已经给cnteacher反馈了。

Nginx实例代码:
server {
listen 80;
server_name www.ynog.com ynog.com;

index index.html index.htm index.php;
root /www/www.ynog.com;

#bbs rewrite
location / {
rewrite ^/archiver/((fid|tid)-[\w\-]+\.html)$ /archiver/index.php?$1 last;
rewrite ^/forum-([0-9]+)-([0-9]+)\.html$ /forumdisplay.php?fid=$1&page=$2 last;
rewrite ^/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ /viewthread.php?tid=$1&extra=page%3D$3&page=$2 last;
rewrite ^/space-(username|uid)-(.+)\.html$ /space.php?$1=$2 last;
rewrite ^/tag-(.+)\.html$ /tag.php?name=$1 last;
break;
}

location ~ \.php$ {
include fastcgi_params;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:8694;
fastcgi_param SCRIPT_FILENAME /www/www.ynog.com$fastcgi_script_name;
}

location /www.ynog.com-status {
stub_status on;
access_log off;
}
}

转载自:http://www.ynog.com/index.php/archives/230

NginxChsHttpLimit zoneModule

本模块可以针对条件,进行会话的并发连接数控制。(例如:限制每个IP的并发连接数。)

__配置示例__

http {
: limit_zone   one  $binary_remote_addr  10m;

: ...

: server {

: ...

: location /download/ {
: limit_conn   one  1;
: }

指令

  • [#limit_zone limit_zone]
  • [#limit_conn limit_conn]

Template:Anchor

limit_zone

语法: limit_zone zone_name $variable the_size

默认值: no

作用域: http

本指令定义了一个数据区,里面记录会话状态信息。
$variable 定义判断会话的变量;the_size 定义记录区的总容量。

例子:

limit_zone   one  $binary_remote_addr  10m;

定义一个叫“one”的记录区,总容量为 10M,以变量 $binary_remote_addr 作为会话的判断基准(即一个地址一个会话)。
您可以注意到了,在这里使用的是 $binary_remote_addr 而不是 $remote_addr。

$remote_addr 的长度为 7 至 15 bytes,会话信息的长度为 32 或 64 bytes。而 $binary_remote_addr 的长度为 4 bytes,会话信息的长度为 32 bytes。

当区的大小为 1M 的时候,大约可以记录 32000 个会话信息(一个会话占用 32 bytes)。
Template:Anchor

limit_conn

语法: limit_conn zone_name the_size

默认值: no

作用域: http, server, location

指定一个会话最大的并发连接数。当超过指定的最发并发连接数时,服务器将返回 “Service unavailable” (503)。

例子:

limit_zone   one  $binary_remote_addr  10m;

: server {
: location /download/ {
: limit_conn   one  1;
: }

定义一个叫“one”的记录区,总容量为 10M,以变量 $binary_remote_addr 作为会话的判断基准(即一个地址一个会话)。限制 /download/ 目录下,一个会话只能进行一个连接。简单点,就是限制 /download/ 目录下,一个IP只能发起一个连接,多过一个,一律503。

转载自:NginxChsHttpLimit zoneModule

PHP FastCGI 进程管理器: PHP-FPM

网址:

最近 PHP-FPM (PHP FastCGI Process Manager) 这个话题在讨论组里很受关注。使用 PHP 的朋友对于 FastCGI 进程的管理估计都很头疼,比如 Nginx 下的 FastCGI 就有不少人用的 Lighttpd 的 spawn-fcgi 来对进程进行管理。但这样存在不少缺点(中文版本)。

PHP-FPM 配置起来很简单,但有一点比较有意思的是如何确定 Worker 的数量。PHP-FPM 作者 Andrei Nigmatulin 在新闻组里提到的小技巧如下:

1) 用 Linux top 命令观察 (这个方式比较土)
2) 用 'netstat -np | grep 127.0.0.1:9000' 收集数据。
设置  php-fpm.conf 中的 max_children 的数值使 等待的数量变为最小。

目前使用 PHP-FPM 还只是通过 Patch 方式,然后编译,期待能够早点并入正式的 PHP 代码中。当然,PHP 核心开发的那些大爷们也不知都在忙什么呢,莫非还在为 Unicode 较劲呢?

PHP-FPM高负载技巧 (PHP-FPM on highload tips)

When you running a highload website with PHP-FPM via FastCGI, the following tips may be useful to you : )
如果您高负载网站使用PHP-FPM管理FastCGI,这些技巧也许对您有用:)

1. Compile PHP’s modules as less as possible, the simple the best (fast);
1.尽量少安装PHP模块,最简单是最好(快)的

2. Increas PHP FastCGI child number to 100 and even more. Sometime, 200 is OK! ( On 4GB memory server);
2.把您的PHP FastCGI子进程数调到100或以上,在4G内存的服务器上200就可以
注:我的1g测试机,开64个是最好的,建议使用压力测试获取最佳值

3. Using SOCKET PHP FastCGI, and put into /dev/shm on Linux;
3.使用socket连接FastCGI,linux操作系统可以放在 /dev/shm中
注:在php-fpm.cnf里设置
<value name=”listen_address”>/tmp/nginx.socket</value>就可以通过socket连接FastCGI了,/dev/shm是内存文件系统,放在内存中肯定会快了

4. Increase Linux “max open files”, using the following command (must be root):
# echo ‘ulimit -HSn 65536′ >> /etc/profile
# echo ‘ulimit -HSn 65536 >> /etc/rc.local
# source /etc/profile
4.调高linux内核打开文件数量,可以使用这些命令(必须是root帐号)
echo ‘ulimit -HSn 65536’ >> /etc/profile
echo ‘ulimit -HSn 65536’ >> /etc/rc.local
source /etc/profile
注:我是修改/etc/rc.local,加入ulimit -SHn 51200的

5. Increase PHP-FPM open file description rlimit:
# vi /path/to/php-fpm.conf
Find “<value name=”rlimit_files”>1024</value>”
Change 1024 to 4096 or higher number.
Restart PHP-FPM.
5. 增加 PHP-FPM 打开文件描述符的限制:
# vi /path/to/php-fpm.conf
找到“<value name=”rlimit_files”>1024</value>”
把1024 更改为 4096 或者更高.
重启 PHP-FPM.

6. Using PHP code accelerator, e.g eAccelerator, XCache. And set “cache_dir” to /dev/shm on Linux.
6.使用php代码加速器,例如 eAccelerator, XCache.在linux平台上可以把`cache_dir`指向 /dev/shm

来源:http://groups.google.com/group/highload-php-en/browse_thread/thread/e48a9fce7ee116ab/db412d43c1c3f36a

转载自:http://willko.javaeye.com/blog/333270

2009年六月
« 5月   7月 »
1234567
891011121314
15161718192021
22232425262728
2930