我需要将nginx服务器更改为lighttpd服务器。 CMS应在支持URL重写的Web服务器上运行。下面提供了工作nginx配置。问题是将nginx配置转换为lighttpd配置。
server {
# The port to listen on
listen 8086;
# The host to listen on
#server_name localhost
# The root directory
root /storage/emulated/0/htdocs/web/;
# Enable directory listing
#autoindex on;
autoindex on;
# Don't show any server tokens
server_tokens off;
# The default indexes to look for
index index.html index.htm index.php;
location / { try_files $uri /index.php?$args; }
location /api/authorize { try_files $uri /api/authorize/index.php?args; }
location /api { try_files $uri /api/index.php?$args; }
location /install { try_files $uri /install/index.php?$args; }
location /maint { try_files $uri /maint/index.php?$args; }
location /maintenance { try_files $uri /index.php?$args; }
}
答案 0 :(得分:0)
我不太明白你的意思,但你可以尝试类似以下示例的lighttpd重写规则:
url.rewrite-once
在处理之前,在网络服务器内部重写一组网址。
e.g。
url.rewrite-once = ( "<regex>" => "<relative-uri>" )
或多个规则..
url.rewrite-once = (
"<regex1>" => "<relative-uri1>",
"<regex2>" => "<relative-uri2>"
)
url.rewrite-repeat
在处理之前,在网络服务器内部重写一组网址
e.g。
url.rewrite-repeat = ( "<regex>" => "<relative-uri>" )
这些选项之间的区别在于,虽然url.rewrite-repeat允许在一行中应用多个(单独定义的)重写规则,但如果表达式匹配,url.rewrite-once将导致跳过进一步的重写规则。因此,url.rewrite-once表现得像Apaches的RewriteRule ... [L]:http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriterule
选项url.rewrite
和url.rewrite-final
已映射到url.rewrite-once in 1.3.16.
url.rewrite-[repeat-]if-not-file
新:从1.4.24开始的1.4.x分支或从svn开始的r2647:
在处理Web服务器之前在网络服务器内部重写一组URL并检查文件是否存在。
从上面举例说明,这是模仿Apache的“!-f”RewriteRule。请注意,这不适用于目录,管道,套接字等。
我想在哪里使用它?也许用例如Drupal后端,其中mod_magnet(具有Apache的-f和-d解决方案)可能不方便或仅仅“太多”这种重写。
正则表达式 模式(“通配符”)与字符串匹配 特殊字符(参见[http://www.regular-expressions.info/reference.html]):
^(/(?!(favicon.ico$|js/|images/)).*)" => "/fgci/$1"l
正常的字母数字字符被视为正常
替换模式
如果匹配的正则表达式包含括号中的组,则替换中的$ 1 .. $ 9将引用捕获的文本
匹配组“$ 1”表示第一组,“$ 2”表示第二组,依此类推。请注意,%
目标中的(like %1, %2, %0, etc.)
替换url.rewrite-*
是允许的,但不具备evhost.path-pattern中的含义。如果在正则表达式条件中指定了url.rewrite- *,则%
模式将由条件正则表达式中的相应组替换。 %1
替换为第一个子表达式,%2
替换为第二个,等等。%0
被匹配正则表达式的整个子字符串替换。请参阅下文,了解使用“%0
”的示例。
实例
正则表达式匹配用户提供的完整REQUEST_URI
,包括
查询字符串。
# the following example, is, however just simulating vhost by rewrite
# * you can never change document-root by mod_rewrite
# use mod_*host instead to make real mass-vhost
server.document-root = "/www/htdocs/"
$HTTP["host"] =~ "^.*\.([^.]+\.com)$" {
url.rewrite-once = ( "^/(.*)" => "/%0/$1" )
}
# request: http://any.domain.com/url/
# before rewrite: REQUEST_URI="/www/htdocs/url/"
# and DOCUMENT_ROOT="/www/htdocs/" %0="any.domain.com" $1="url/"
# after rewrite: REQUEST_URI="/www/htdocs/any.domain.com/url/"
# still, you have DOCUMENT_ROOT=/www/htdocs/
# please note, that we have two regular expressions: the one which
# $HTTP["host"] is been compared with, and the one of the rewrite rule.
# the numbered subexpressions available to build the relative uri are
# being prefixed by '%' for subexpressions of the first regular expression
# match and by '$' for subexpressions of the second one.
# subexpression 0 interpolates the whole matching string: %0 for the whole
# string matching the conditional, and $0 for the whole string matching the
# rewrite rule.
# if the rewrite rule is not included in a conditional
# block, only the '$' prefixed variables are available.
url.rewrite-once = ( "^/id/([0-9]+)$" => "/index.php?id=$1",
"^/link/([a-zA-Z]+)" => "/index.php?link=$1" )
mod_redirect
重写规则始终在重定向规则之前执行。无论模块加载的顺序或配置中的规则顺序如何(lighttpd v1.4.13)都是如此。但是,mod_rewrite提供了一种通过unmangled传递URL的机制:指定“$0
”作为规则目标,但请确保规则与整个字符串匹配,因为$0
是整个匹配的字符串。
e.g。
url.rewrite-once = (
"^/foo" => "$0",
"^/(.*)" => "/handler/$1"
)
url.redirect = (
"^/foo" => "http://foo.bar/"
)
从版本1.4.40开始,另一种方法是为重写规则指定一个空白目标。这将导致匹配的规则保持未修改的URL,并将跳过任何进一步的重写规则。
url.rewrite-once = (
"^/foo" => "", # instead of (nonsensical) blank url, the url will not be modified
"^/(.*)" => "/handler/$1"
)
Windows上“文件名太长”的解决方法
在Windows上运行Lighttpd时,如果计算的文件名长度超过255个符号,则可能会出现500内部服务器错误。
在错误日志中,将找不到(response.c.537)
文件...左右:文件名太长/very_looooong_path ->
。
解决方法是使用mod_rewrite来避免此错误。
server.modules += ("mod_rewrite")
url.rewrite-once = ( ".{250,}" => "/toolong.php" )
如果错误处理程序是PHP,$_SERVER['REQUEST_URI']
将包含完整的URI。
传递/匹配查询字符串(GET variables)
如果您想将查询字符串(?foo=bar)
传递给重写目标,则必须明确匹配它:
url.rewrite-once = (
"^/news/([^\?]+)(\?(.*))?" => "/news.php?title=$1&$3"
)