Rewrite obfuscated

Manlio Perillo manlio_perillo at libero.it
Thu Jan 17 17:57:07 MSK 2008


Aleksandar Lazic ha scritto:
> Hi Matteo,
> 
> On Mit 16.01.2008 16:34, Matteo Niccoli wrote:
>> Hi all,
>>
>> I need help with nginx rewrite. Basically, I need to write a rewrite
>> like this:
>>
>> location /try/ {
>>     rewrite ^(.*)$ http://www.foo.com/index.php=?1 last;
>> }
>>
>> But, if it's possible, without rewrite the url on browser, but simple
>> pass the $1 to the replacement string, without change the URL.
> 
> Similar to apaches rewrite rule 'passthrough'
> 
> http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriterule
> 
>> It's possible? thanks!
> 
> AFAIK not yet.
> 

It is possible to do something like this:

location ~* /foo/ {
     set $rewrite_uri "";

     if ($uri ~* ^/foo/(.*)$) {
         set $rewrite_uri  $1;
     }

     log_format  custom  '$remote_addr $request '
                         '"$status" "$http_user_agent" <$rewrite_uri>';
     access_log  logs/access.log  custom;

     proxy_set_header Host $http_host;
     proxy_pass http://127.0.0.1:8080/$rewrite_uri;
}


But I'm not sure if this is the best solution; moreover it is likely to 
break urls in the proxied application (if they are relative and not 
absolute).

Note that this requires nginx 0.6.x.


> Cheers
> 
> Aleks
> 
> 


Manlio Perillo





More information about the nginx mailing list