Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying hard to make my code work on nginx. This configuration works with lighttpd but I want migrate it to nginx.

Rewrite rules on lighttd :

url.rewrite-once = (
 "^/(ui)/(.*)$" => "/gi.php/$1/$2",
 "/(.*)\.(.*)" => "$0",
 "/(xhr|js-api)/(.*)" => "$0",
 "^/([^.]+)$" => "/gi.php/$1"
)

Can anyone help in this conversion? I tried using lot of things, including converting it to apache rewrite rules, but none of them worked.

Nginx rule:

if (!-f $request_filename){
       set $rule_0 1$rule_0;
}
if (!-d $request_filename){
       set $rule_0 2$rule_0;
}
if ($rule_0 = "21"){
       rewrite ^/(.*)$ /gi.php/$1 last;
}

Error : 404

Any suggestions?

share|improve this question

1 Answer 1

You don't generally do rewrites in nginx, the same way you do them in Apache or lighttpd. Most such things should be replaced with try_files instead.

A trivial example:

try_files $uri $uri/ /gi.php

See the nginx documentation for more details.

share|improve this answer
    
I tried the approach but it didnt work, it worked initially loading the page, but not for others. –  user3355434 Feb 28 at 3:12
    
At least you are on the right track now. –  Michael Hampton Feb 28 at 3:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.