Convert lighttpd rewrite rule to nginx

Igor Sysoev igor at sysoev.ru
Tue Jul 24 06:49:25 UTC 2012


On Jul 24, 2012, at 5:23 , justin wrote:

> I have the following simple lighttpd rewrite rule:
> 
>    $HTTP["host"] =~ "^(app\.mydomain\.com)$" {
>        url.rewrite-once = (
>                "^[^.]*$" => "controller.php/$1"
>        )
>    }
> 
> I am trying to port this rule to nginx and have the following:
> 
>    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;
> }
> 
> The problem is that the rewrite rule for nginx is not working correctly?
> Any idea what I am doing wrong?
> 

server {
    server_name   app.mydomain.com;

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

    location ~ ^[^.]+$ {
        fastcgi_intercept_errors on;
        fastcgi_param SCRIPT_FILENAME $document_root/controller.php;
        fastcgi_param PATH_INFO $uri;
        fastcgi_pass 127.0.0.1:9000;
        include fastcgi_params;
    }

    ...
}



--
Igor Sysoev



More information about the nginx mailing list