# Nginx fiasco

**URL:** <https://www.ruby-forum.com/t/nginx-fiasco/206109>\
**Category:** NGINX\
**Created:** [April 22, 2011, 10:39am UTC](https://www.ruby-forum.com/t/nginx-fiasco/206109 "2011-04-22T10:39:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [April 22, 2011, 10:39am UTC](https://www.ruby-forum.com/t/nginx-fiasco/206109/1 "2011-04-22T10:39:37Z")

</div>

Hey guys,

I am giving out the apache rewrite config and the config i wrote for  
nginx. I am not able to get the rewrite rules to work. Please help me  
get rid of the problem.

Some other useful details :

1. the apache rewrite rules are of .htacces file present under a  
directory admin under www. i.e the path is /var/www/admin for the  
.htaccess file.

2. I placed the nginx conf rules straight under nginx.conf present  
/etc/nginx/nginx.conf

3. When i installed nginx , i used the command " apt-get install nginx "  
on ubuntu, so i did not activate or disable any module installation.

4. I have also installed the Perl Regular Expression Library explicitly,  
so i dont think that should be an issue.

5. Another point, dont know how much useful. I am tryin to install a  
classifieds module i bought named ‘ikiclassifieds’ . Now its  
installation occurs through its own php file (install2.php) inside the  
admin folder. I got to run it and it checks some settings, and if fine,  
installs.  
So, one of its setting’s telling me that my rewrite mode is off, and i  
cant understand why. The readme told me to type  
[http://yourdomain.com/admin/install](http://yourdomain.com/admin/install) in my browser to start installation,  
so i wrote [http://localhost/admin/install](http://localhost/admin/install) . Now, it doesnt show up  
anything clearly proving the rewrites arent working.  
Another thing that i noticed was. in the php code for installation, it  
was checking if a variable ‘page’ in the GET part of url had value  
‘install’ and this comes through the rewrites (refer code below). When i  
tried tweaking it by passing the variable in GET myself a[/b]nd start  
installation, the url changed to install.htm and it showed 404 error, so  
it was to rewrite from htm to php which it didnt…  
phew…this point was a long one Tongue

* * *

Apache .htaccess config =\>

Options +FollowSymLinks

RewriteEngine on

RewriteBase /admin

RewriteCond %{REQUEST\_URI} (/|.htm|.html|/[^.]\*)$ [NC]

RewriteCond %{REQUEST\_FILENAME} !-f

RewriteCond %{REQUEST\_FILENAME} !-d

#RewriteRule ^rss([0-9]{0,}),(.\*).html$ rss.php?cat=$1 [L]

RewriteRule (.\*) index.php?page=$1

RewriteRule templates/(.\*).tpl$ index.php[F]

RewriteRule templates\_c/(.\*) index.php[F]

RewriteRule configs/(.\*).conf$ index.php [F]

#RewriteRule ^p-(.\*).html$ index.php?page=$1 [L]

* * *

Nginx config =\>

server  
{  
listen 80;  
server\_name localhost;  
root /var/www/admin;

location /  
{  
if (!-e $request\_filename){  
rewrite ^(.\*)$ /index.php?page=$1 last;  
break;  
}  
}

location ~\* .(/|.htm|.html|/[^.]\*)$  
{  
try\_files $uri $uri/ index.php?page=$uri;  
}

location = “/install” #added this coz i thgt maybe the first wasnt being  
accepted  
{  
try\_files $uri $uri/ index.php?page=$uri;  
}

location /templates/  
{  
rewrite ^(.\*).tpl$ index.php permanent;  
}

location /templates\_c/  
{  
rewrite ^(.\*) index.php permanent;  
}

location /configs/  
{  
rewrite ^(.\*).conf$ index.php permanent;  
}  
}
