将lighttpd重写规则转换为nginx

时间:2012-07-24 00:35:05

标签: mod-rewrite nginx rewrite lighttpd

我有以下简单的lighttpd重写规则:

$HTTP["host"] =~ "^(app\.mydomain\.com)$" {
    url.rewrite-once = (
            "^[^.]*$" => "controller.php/$1"
    )
}

我正在尝试将此规则移植到nginx并具有以下内容:

server {
  listen 80;

  server_name app.mydomain.com;

  if ($host = 'app.mydomain.com') {
    rewrite ^[^.]*$ controller.php/$1 last;
  }

  root /srv/www/domains/app.mydomain.com;

  index index.php;

  access_log /var/log/nginx/domains/app.mydomain.com/access.log;
  error_log /var/log/nginx/domains/app.mydomain.com/error.log;

  include /etc/nginx/excludes.conf;
  include /etc/nginx/php.conf;
  include /etc/nginx/expires.conf;
}

问题是nginx的重写规则无法正常工作?知道我做错了什么吗?感谢。

1 个答案:

答案 0 :(得分:0)

你需要在controller.php前面加一个斜杠,你可能不需要重写if块,因为它仍然是vhost的服务器名。

rewrite ^[^.]*$ /controller.php/$1 last;