i just found this site which has a converter for htaccess files - to create nginx files from them: http://winginx.com/htaccess
i use the elgg framework (www.elgg.org) and i ran the htaccess file that comes with the elgg framework through this tool and the nginx config that was produced is running fine in my local development server - however, on my live server i am served a file for download instead of html pages when i use this same new config.
the problematic lines are - in the original htaccess:
# Everything else that isn't a file gets routed through the page handler
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([A-Za-z0-9\_\-]+)$ engine/handlers/page_handler.php?handler=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([A-Za-z0-9\_\-]+)\/(.*)$ engine/handlers/page_handler.php?handler=$1&page=$2 [QSA,L]
----------------------------
and they are converted to:
location / {
if (!-e $request_filename){
rewrite ^/([A-Za-z0-9\_\-]+)$ /engine/handlers/page_handler.php?handler=$1 break;
}
if (!-e $request_filename){
rewrite ^/([A-Za-z0-9\_\-]+)\/(.*)$ /engine/handlers/page_handler.php?handler=$1&page=$2 break;
}
}
-------------------
and the nginx config i was already using (which i did not create) handles this part of the config using:
if (!-d $request_filename){
set $rule_11 1$rule_11;
}
if (!-f $request_filename){
set $rule_11 2$rule_11;
}
if ($rule_11 = "21"){
rewrite ^/([A-Za-z0-9\_\-]+)$ /engine/handlers/page_handler.php?handler=$1;
}
if (!-d $request_filename){
set $rule_12 1$rule_12;
}
if (!-f $request_filename){
set $rule_12 2$rule_12;
}
if ($rule_12 = "21"){
rewrite ^/([A-Za-z0-9\_\-]+)\/(.*)$ /engine/handlers/page_handler.php?handler=$1&page=$2;
}
-------
in my research into the nginx manual/docs/wiki i concluded that try_files should be used to replace these various versions..
so far i have not had success with try_files either and testing is tricky because this is only occurring on my production server and i am unclear on why that is.
any tips welcomed! thanks