关于lighttpd的资料
分页: 1/1 第一页 1 最后页 [ 显示模式: 摘要 | 列表 ]
Nov 7
点击在新窗口中浏览此图片

图:更换lighttpd+php fast-cgi的变化

原先服务器是apache的,加载php5模块,还有mysql运行,但一直负载很高,把mysql用到局域网的另外一个机器,占用CPU更加高,快疯了。可能apache进程太多,每个进程都吃太多内存了?具体原因不知道。

昨天晚上把php-fastcgi安装好了,打包文件见新浪的资料共享:
http://ishare.iask.sina.com.cn/cgi-bin/fileid.cgi?fileid=4537134

安装好后,把apache的日志对应lighttpd写好,转换好之前的配置,然后发现一个问题,rewrite后的url已经是变化了的,大家要注意(示例说明):


$HTTP["host"] == "test.aslibra.com" {
  url.rewrite-once = (
        "^/s" => "/__s.php",
  )
  server.document-root = "/Data/webapps/test.aslibra.com"
        $HTTP["url"] =~ "^\/__s" {
        accesslog.filename = "|/Data/apps/cronolog/sbin/cronolog /log/%Y/%m/%d/sub.%m%d%H"
        }
}


启动后,负载变轻了好多好多,流量还正常。
看来php的fast-cgi应该好好配置好,apache的确有点重了。。
不过今天有发现假死情况,重启也无法启动lighttpd,不知道是否php-cgi占用内存多了还是啥,有待观察。。。
Tags:
Oct 16
今天发现上传不了图片了,还以为是程序出问题了。

PHP上传文件是类似的错误
引用
Array(
    [name] => 1711.jpg
    [type] =>
    [tmp_name] =>
    [error] => 6
    [size] => 0
)


检查磁盘,网站目录都还正常,还有200G空间呢,不可能出现这样的问题。就发现根目录已经使用了百分之九十多了,具体数值忘记了,可能是系统保护的预留的空间。

重启了一下lighttpd,发现有如下提示:

引用
2008-10-16 11:50:49: (mod_compress.c.415) couldn't create directory for file /tmp/lighttpd/cache/compress/12798222/index.htm-gzip-64391395-13510-1215020773

[root@localhost lighttpd]# xc_fcntl_create: open(/tmp/.xcache.2.0.1804289383.lock, O_RDWR|O_CREAT, 0666) failed:PHP Fatal error:  XCache: can't create lock in Unknown on line 0
PHP Fatal error:  XCache: failed init opcode cache in Unknown on line 0

[root@localhost lighttpd]# 2008-10-16 11:53:50: (mod_fastcgi.c.1743) connect failed: No such file or directory on unix:/tmp/php.socket-3


第一个是lighttpd的compress的模块,是写入文件的
第二个是XCache的临时目录写入
第三个是php的socket文件

看来是tmp目录所在的分区满了。
大体应该是lighttpd使用的压缩文件占用空间越来越大,导致空间不足,把lighttpd的compress目录重新设置到富裕的分区就好,然后把tmp目录的压缩文件目录都删掉即可。
Tags: ,
Aug 19
lighttpd做判断的时候可以很灵活,比如:

$HTTP["host"] == "www.example.org" {
  $HTTP["remoteip"] != "10.0.0.0/8" {
   url.access-deny = ( "" )
  }
}


$HTTP数组里面有如下的变量可以引用(官方):
引用
$HTTP["cookie"]
match on cookie
$HTTP["host"]
match on host
$HTTP["useragent"]
match on useragent
$HTTP["referer"]
match on referer
$HTTP["url"]
match on url. If there are nested blocks, this must be the most inner block.
$HTTP["querystring"]
match on querystring, eg, after the ? in this type url: index.php?module=images..
$HTTP["remoteip"]
match on the remote IP or a remote Network (Warning: doesn't work with IPv6 enabled)
$HTTP["scheme"] (Introduced in version 1.4.19)
match on the scheme used by the incoming connection. This is either "http" or "https".
$SERVER["socket"]
match on socket. Value must be on the format "ip:port" where ip is an IP address and port a port number, or ":port" to match port only. Only equal match (==) is supported. It also binds the daemon to this socket. Use this if you want to do IP/port-based virtual hosts.
$PHYSICAL["path"] (Introduced in version 1.5.0)
match on the mapped physical path of the file / cgi script to be served.
$PHYSICAL["existing-path"] (Introduced in version 1.5.0)
match on the mapped physical path of the file / cgi script to be served only if such a file exists on the local filesystem.
Tags:
Jul 16
$HTTP["host"] == "a.aslibra.com" {
       proxy.server = ( "" =>
                  ( (
                      "host" => "b.aslibra.com"
                    ) )
        )
}


这样的代码在apache里面是正常的,今天使用lighttpd就发现出现 500 的内部错误。
于是查资料,看看lighttpd的官方说明:

引用
<extension>: is the file-extension or prefix (if started with "/") might empty to match all requests
"host": is ip of the proxy server ''DO not use hostnames here! only IP Addresses''
"port": is tcp-port on the "host" used by the proxy server (default: 80)


也就是不允许用域名了,不知道是否正常,可以测试一下:

做个PHP文件:

proxy.php
<?
ob_start();
print_r($_SERVER);
$a=ob_get_contents();
file_put_contents("log.txt",$a);
?>


得到代码:
wget http://127.0.0.1/proxy.php
引用
   [SERVER_NAME] => 127.0.0.1
   [GATEWAY_INTERFACE] => CGI/1.1
   [SERVER_PORT] => 80
   [SERVER_ADDR] => 127.0.0.1
   [REMOTE_PORT] => 50677
   [REMOTE_ADDR] => 127.0.0.1


指定proxy和hosts文件:
127.0.0.1 proxy.aslibra.com

$HTTP["host"] == "proxy.aslibra.com" {
       proxy.server = ( "" =>
                  ( (
                      "host" => "127.0.0.1",
                      "port" => 80
                    ) )
        )
}


引用
   [SERVER_NAME] => proxy.aslibra.com
   [GATEWAY_INTERFACE] => CGI/1.1
   [SERVER_PORT] => 80
   [SERVER_ADDR] => 127.0.0.1
   [REMOTE_PORT] => 50676
   [REMOTE_ADDR] => 127.0.0.1


也就是发送的还是当前的主机域名,所以proxy也不用担心只是按IP访问,和正常的代理一样。

但是,这样的话,如果域名指向有变化,那这里就不方便了,apache里面可以用域名的方式,那其实可以不用担心域名指向变化,但lighttpd这样肯定对效率有很大的提高。
Tags: ,
Jul 13
Lighttpd是一个德国人领导的开源软件,其根本的目的是提供一个专门针对高性能网站,安全、快速、兼容性好并且灵活的web server环境。具有非常低的内存开销,cpu占用率低,效能好,以及丰富的模块等特点。lighttpd是众多OpenSource轻量级的web server中较为优秀的一个。支持FastCGI, CGI, Auth, 输出压缩(output compress), URL重写, Alias等重要功能,而Apache之所以流行,很大程度也是因为功能丰富,在lighttpd上很多功能都有相应的实现了,这点对于apache的用户是非常重要的,因为迁移到lighttpd就必须面对这些问题。




lighttpd的url重写:

引用
URL 重写是截取传入 Web 请求并自动将请求重定向到其他 URL 的过程。url重写的优点在于:

a.缩短url,隐藏实际路径提高安全性;
b.易于用户记忆和键入;
c. 易于被搜索引擎收录。

lighttpd(http://lighttpd.net/)是一款轻量级的web server,和apache一样是开源的,与apache相比,

虽然功能不及apache完善,稳定性也不如apache,但是,不管是服务静态页面,还是服务动态内容(CGI,

PHP),它都比apache快,用于ad banner之类的WEB服务器是最恰当不过了。采用lighttpd的网站不少,最

著名的是豆瓣(http://www.douban.com)。

然而,我发现网上介绍lighttpd的url重写技术的文章非常少,所以我将资料整理在这里,方便各位查看



lighttpd的url重写非常简单,只要打开lighttpd.conf文件,(该文件一般在/usr/local/etc/目录下,

如果不是自己安装的,可以用find命令找到),找到url.rewrite-once = ( ),在括号中写url重写规则

就可以了。以下是某个网站的例子:

 url.rewrite-once = (
"^/rank/([0-9]+).html$" =>"/rank.php?pid=$1",
"^/(w+)/?$" =>"/userinfo.php?puser=$1",
"^/detail/([0-9]+).html$" =>"/detail.php?id=$1"
)
分页: 1/1 第一页 1 最后页 [ 显示模式: 摘要 | 列表 ]