在 Ubuntu 上搭建 L2MP 服务器

包含网卡/无线网的网络问题和ADSL/校园网/宽带拨号支持及代理/共享等网络使用问题
回复
头像
ssjjxx000
帖子: 201
注册时间: 2006-01-09 9:41
来自: 湖南邵东

在 Ubuntu 上搭建 L2MP 服务器

#1

帖子 ssjjxx000 » 2008-07-19 9:11

L2MP (Linux+Lighttpd+MySQL+PHP) 使用轻量级的 lighttpd 作为 Web 服务器,虽然名字没有 Apache 那么响亮,但用它搭建的网站却不少,如: Sourceforge、Meebo、豆瓣、猫眼宽频 这些。lighttpd 以安全、快速和内存消耗低著称,还专门为大型分布式连接环境做了优化,流行使用在基于 AJAX 或 Ruby on Rails 应用的网站。

引用 Zhiqiang 对它的介绍:lighttpd 是德国人开发的一款开源软件,其根本的目的是提供一个专门针对高性能网站,安全、快速、兼容性好并且灵活的 Web Server 环境。具有非常低的内存开销,CPU 占用率低,效能好,以及丰富的模块等特点。lighttpd 是众多 OpenSource 轻量级的 Web Server 中较为优秀的一个,支持FastCGI, CGI, Auth, 输出压缩 (output compress), URL 重写, Alias 等重要功能,而 Apache 之所以流行,很大程度也是因为功能丰富,在 lighttpd 上很多功能都有相应的实现了,这点对于 Apache 的用户是非常重要的,因为迁移到 lighttpd 就必须面对这些问题。

接下来就介绍一下在 Ubuntu 上快速搭建使用 lighttpd 的 L2MP Web 服务器。

1、安装 Lighttpd+MySQL+PHP5

sudo apt-get install lighttpd mysql-server php5-cgi phpmyadmin

2、配置 10-fastcgi.conf

先备份
sudo cp /etc/lighttpd/conf-available/10-fastcgi.conf /etc/lighttpd/conf-available/10-fastcgi.conf.bak

然后,编辑
sudo gedit /etc/lighttpd/conf-available/10-fastcgi.conf

把原有内容删除,用以下内容替换掉
server.modules += ( "mod_fastcgi" )
fastcgi.server = ( ".php" =>
( "localhost" =>
( "socket" => "/tmp/php5-fcgi.socket",
"bin-path" => "/usr/bin/php5-cgi" )))

3、开启 fastCGI

sudo lighty-enable-mod fastcgi

4、重启服务器

sudo /etc/init.d/lighttpd restart

搞定,现在就可以使用 http://localhost/ 浏览运行在 lighttpd 上的网站了。以上方法在 Ubuntu Edgy, Feisty 上测试通过,还是记住以下几个命令和位置就行了。

sudo /etc/init.d/lighttpd restart (重启 lighttpd)
sudo gedit /etc/lighttpd/lighttpd.conf (配置 lighttpd)
sudo gedit /etc/php5/cgi/php.ini (配置 PHP)
sudo gedit /etc/mysql/my.cnf (配置 MySQL)
/var/www/(主目录位置)
头像
toawinner47
帖子: 200
注册时间: 2006-11-08 20:46
联系:

[问题]请问楼主lighttpd.conf如何设置

#2

帖子 toawinner47 » 2008-09-04 1:00

我的lighttpd.conf设置如下:

代码: 全选

# Debian lighttpd configuration file
# 

############ Options you really have to take care of ####################

## modules to load
# mod_access, mod_accesslog and mod_alias are loaded by default
# all other module should only be loaded if neccesary
# - saves some time
# - saves memory

server.modules              = ( 
            "mod_access",
	    "mod_fastcgi",
            "mod_alias",
            "mod_accesslog",
            "mod_compress",
            "mod_rewrite", 
            "mod_redirect", 
            "mod_status", 
	    "mod_evhost",
#           "mod_usertrack",
#           "mod_rrdtool",
#           "mod_webdav",
#           "mod_expire",
#           "mod_flv_streaming",
#           "mod_evasive"
 )

## a static document-root, for virtual-hosting take look at the 
## server.virtual-* options
server.document-root       = "/var/www/"

## where to send error-messages to
server.errorlog            = "/var/log/lighttpd/error.log"

## files to check for if .../ is requested
index-file.names           = ( "index.php", "index.html",
                               "index.htm", "default.htm",
                               "index.lighttpd.html" )


## Use the "Content-Type" extended attribute to obtain mime type if possible
# mimetype.use-xattr = "enable"

#### accesslog module
accesslog.filename         = "/var/log/lighttpd/access.log"

## deny access the file-extensions
#
# ~    is for backupfiles from vi, emacs, joe, ...
# .inc is often used for code includes which should in general not be part
#      of the document-root
url.access-deny            = ( "~", ".inc" )

##
# which extensions should not be handle via static-file transfer
#
# .php, .pl, .fcgi are most often handled by mod_fastcgi or mod_cgi
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )

 
######### Options that are good to be but not neccesary to be changed #######

## bind to port (default: 80)
server.port               = 80

## bind to localhost only (default: all interfaces)
server.bind                = "192.168.0.101"

## error-handler for status 404
#server.error-handler-404  = "/error-handler.html"
#server.error-handler-404  = "/error-handler.php"

## to help the rc.scripts
server.pid-file            = "/var/run/lighttpd.pid"

## 
## Format: <errorfile-prefix><status>.html
## -> ..../status-404.html for 'File not found'
#server.errorfile-prefix    = "/var/www/"

## virtual directory listings
dir-listing.encoding        = "utf-8"
server.dir-listing          = "enable"

## send unhandled HTTP-header headers to error-log
#debug.dump-unknown-headers  = "enable"

### only root can use these options
#
# chroot() to directory (default: no chroot() )
#server.chroot            = "/"

## change uid to <uid> (default: don't care)
server.username            = "www-data"

## change uid to <uid> (default: don't care)
server.groupname           = "www-data"

#### compress module
compress.cache-dir          = "/var/cache/lighttpd/compress/"
compress.filetype           = ("text/plain", "text/html", "application/x-javascript", "text/css")

#### status module
# status.status-url = "/server-status"
# status.config-url = "/server-config"

#### url handling modules (rewrite, redirect, access)
# url.rewrite                 = ( "^/$"             => "/server-status" )
# url.redirect                = ( "^/wishlist/(.+)" => "http://www.123.org/$1" )

#
# define a pattern for the host url finding
# %% => % sign
# %0 => domain name + tld
# %1 => tld
# %2 => domain name without tld
# %3 => subdomain 1 name
# %4 => subdomain 2 name
#
# evhost.path-pattern = "/home/storage/dev/www/%3/htdocs/"

#### expire module
# expire.url                  = ( "/buggy/" => "access 2 hours", "/asdhas/" => "access plus 1 seconds 2 minutes")

#### rrdtool
# rrdtool.binary = "/usr/bin/rrdtool"
# rrdtool.db-name = "/var/www/lighttpd.rrd"


#### variable usage:
## variable name without "." is auto prefixed by "var." and becomes "var.bar"
#bar = 1
#var.mystring = "foo"

## integer add
#bar += 1
## string concat, with integer cast as string, result: "www.foo1.com"
#server.name = "www." + mystring + var.bar + ".com"
## array merge
#index-file.names = (foo + ".php") + index-file.names
#index-file.names += (foo + ".php")


#### external configuration files
## mimetype mapping
include_shell "/usr/share/lighttpd/create-mime.assign.pl"

## load enabled configuration files, 
## read /etc/lighttpd/conf-available/README first
include_shell "/usr/share/lighttpd/include-conf-enabled.pl"

#### handle Debian Policy Manual, Section 11.5. urls
### by default allow them only from localhost
### (This must come last due to #445459)
fastcgi.server             = ( ".php" =>
                               ( "localhost" =>
                                 (
                                   "socket" => "/tmp/php5-fcgi.socket",
                                   "bin-path"  => "/usr/bin/php5-cgi"
                                 )
                               )
                            )
$HTTP[”host”] == “localhost” {
$HTTP["remoteip"] == "192.168.0.101" {
	alias.url += (
		"/doc/" => "/usr/share/doc/",
		"/images/" => "/usr/share/images/"
	)
	$HTTP["url"] =~ "^/doc/|^/images/" {
		dir-listing.activate = "enable"
	}
}

结果出错了:

$ sudo /etc/init.d/lighttpd start
* Starting web server lighttpd Duplicate config variable in conditional 0 global: fastcgi.server
2008-09-04 00:53:15: (configfile.c.855) source: /etc/lighttpd/lighttpd.conf line: 165 pos: 1 parser failed somehow near here: (EOL)
[fail]
头像
toawinner47
帖子: 200
注册时间: 2006-11-08 20:46
联系:

#3

帖子 toawinner47 » 2008-09-04 1:04

出错在165行,google查找了也不知道解决办法
头像
toawinner47
帖子: 200
注册时间: 2006-11-08 20:46
联系:

#4

帖子 toawinner47 » 2008-09-19 1:41

"socket" => "/tmp/php5-fcgi.socket",
"bin-path" => "/usr/bin/php5-cgi"
这两名句应改为

代码: 全选

"socket" => "/tmp/php.socket",   
                                    "bin-path" => "/usr/bin/php-cgi -c /etc/php5/cgi/php.ini",
否则会出现错误:
* Starting web server lighttpd Duplicate config variable in conditional 0 global: fastcgi.server
2008-09-04 00:53:15: (configfile.c.855) source: /etc/lighttpd/lighttpd.conf line: 165 pos: 1 parser failed somehow near here: (EOL) [fail]
gzlsl
帖子: 75
注册时间: 2007-10-19 10:27

Re: 在 Ubuntu 上搭建 L2MP 服务器

#5

帖子 gzlsl » 2008-12-28 2:18

谢谢楼主
我在8.04Desktop上安装没有问题,

还有两个疑问请教一下:
1、网上介绍说L2MP对静态页面的处理能力很好,那对完全的PHP页面的处理性能怎么样,究竟比APACHE好多少?
2、另外,不知道L2MP有什么性能优化的方法没有?
:em01
对各位的回答表示谢谢先!!
回复