首先要说明一下,此次安装的环境是Debian(Etch),使用的服务器软件是Lighttpd,Lighttpd实现伪静态的规则与Apache不同,并不是使用.htaccess的mod_rewrite。大家都知道伪静态能给服务器带来比较好的Seo效果,可以把带有"?"的地址换成比较"干净"的地址,在英文中称之为Clean URLS,很多国外著名的php程序都有这样的选项,如WordPress,Joomla等,本站之前介绍过在WordPress中配置永久链接的方法,点击这里可以查看这篇日志。
进入主题,如何在Lighttpd中配置使之支持Drupal6.4呢,请详细阅读本文。
1,首先要先安装一个Lighttpd模块,用来解析lua文档。
apt-get install lighttpd-mod-magnet
2,然后需要开启它,它会自动在/etc/lighttpd/conf-enabled文件夹中添加模块支持文件10-magnet.conf
lighty-enable-mod magnet
3,进入/etc/lighttpd目录并创建文件drupal.lua
cd /etc/lighttpd
touch drupal.lua
vi drupal.lua
将下面这段代码添加进去。
-- little helper function function file_exists(path) local attr = lighty.stat(path) if (attr) then return true else return false end end function removePrefix(str, prefix) return str:sub(1,#prefix+1) == prefix.."/" and str:sub(#prefix+2) end -- prefix without the trailing slash local prefix = '/drupal' -- the magicSponsored Linksif (not file_exists(lighty.env["physical.path"])) then -- file still missing. pass it to the fastcgi backend request_uri = removePrefix(lighty.env["uri.path"], prefix) if request_uri then lighty.env["uri.path"] = prefix .. "/index.php" local uriquery = lighty.env["uri.query"] or "" lighty.env["uri.query"] = uriquery .. (uriquery ~= "" and "&" or "") .. "q=" .. request_uri lighty.env["physical.rel-path"] = lighty.env["uri.path"] lighty.env["request.orig-uri"] = lighty.env["request.uri"] lighty.env["physical.path"] = lighty.env["physical.doc-root"] .. lighty.env["physical.rel-path"] end end -- fallthrough will put it back into the lighty request loop -- that means we get the 304 handling for free.
![]()
这里有一项是需要你根据需要更改的
-- prefix without the trailing slash
local prefix = ''
如果你是打算将drupal放在目录里面,如放在drupal目录里,那么就设置 local prefix = '/drupal'
4,编辑/etc/lighttpd/lighttpd.conf进行相关配置
主要就是添加magnet的访问路径和阻止访问的文件。
## 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", ".engine", ".install", ".module", ".sh", "sql", ".theme", ".tpl.php", ".xtmpl", "Entries", "Repository", "Root" )## Use Drupal Clean URLS
# magnet.attract-physical-path-to = ( "/etc/lighttpd/drupal.lua" )
然后再在安装了drupal6.4的虚拟主机中添加Drupal Clean URLS规则,如
## drupal.nicelover.cn
$HTTP["host"] =~ "drupal.nicelover.cn$" {
magnet.attract-physical-path-to = ( "/etc/lighttpd/drupal.lua" )
server.document-root = "/home/nicelover/drupal/public_html"
server.errorlog = "/var/log/lighttpd/drupal.nicelover.cn-error.log"
accesslog.filename = "/var/log/lighttpd/drupal.nicelover.cn-access.log"
}
6,最后重启一下Lighttpd就可以了。
/etc/init.d/lighttpd restart
本文参考了
Installing Drupal 6.4 On A Lighttpd Web Server (Debian Etch)