# Nginx rewrite rules



## graudeejs (Sep 24, 2011)

Since I will shutdown my server soon, I decided tho post Nginx rewrite rules, that I used here. They might not be perfect (dokuwiki for example), but it's the best, that I have discovered.

Some of them took very long time to figure you 

If you have some other, useful nginx rewrite rules, post them below
If you see something wrong with these rules, do not hesitate to point that out


*bugzilla*

```
location ~ .*\.(pl|pm)$ {
    deny all;
}

location = /localconfig {
    deny all;
}

location ~ ^/(data|Bugzilla|template) {
    deny all;
}

location ~ ^/docs/(.*)$ {
    index index.html;
    alias /usr/local/share/doc/bugzilla/$1;
}

location ~ .*\.(png|gif|jpg|map)$ {
    allow all;
}

location ~ .*\.cgi$ {
    fastcgi_pass    unix:/var/run/fcgiwrap/fcgiwrap.sock;
    fastcgi_param   PATH_INFO       $fastcgi_script_name;
    fastcgi_param   QUERY_STRING    $query_string;
    fastcgi_param   REQUEST_METHOD  $request_method;
    fastcgi_param   CONTENT_TYPE    $content_type;
    fastcgi_param   CONTENT_LENGTH  $content_length;
    fastcgi_param   SERVER_PROTOCOL $server_protocol;
    fastcgi_param   SERVER_PORT     $server_port;
    fastcgi_param   SERVER_NAME     $server_name;
    include         fastcgi_params;
}
```

*cgit*

```
if (!-f $request_filename) {
    rewrite ^/([^?/]+/[^?]*)?(?:\?(.*))?$ /cgit.cgi?url=$1&$2 last;
}

location ~ .*\.cgi$ {
    fastcgi_pass    unix:/var/run/fcgiwrap/fcgiwrap.sock;
    fastcgi_param   SCRIPT_FILENAME $document_root/cgit.cgi;
    fastcgi_param   CGIT_CONFIG     /path/to/cgit.rc;
    include         fastcgi_params;
}
```

*hgweb*

```
location ~ ^/(.*)?? {
    fastcgi_pass   unix:/var/run/fcgiwrap/fcgiwrap.sock;
    fastcgi_param  PATH_INFO           $fastcgi_script_name;
    fastcgi_param  QUERY_STRING        $query_string;
    fastcgi_param  REQUEST_METHOD      $request_method;
    fastcgi_param  CONTENT_TYPE        $content_type;
    fastcgi_param  CONTENT_LENGTH      $content_length;
    fastcgi_param  SERVER_PROTOCOL     $server_protocol;
    fastcgi_param  SERVER_PORT         $server_port;
    fastcgi_param  SERVER_NAME         $server_name;
    fastcgi_param  SCRIPT_FILENAME     /path/to/hgweb.cgi;
    fastcgi_param  HGWEB_CONFIG        /path/to/hgweb.config;
    include        fastcgi_params;
}
```


*roundcube*

```
location ~ ^/(index\.php)??$ {
    allow all;
    fastcgi_pass    local_php;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

location ~ ^.*\.(css|png|jpg|ico|gif|js|html??)$ {
    allow all;
}

location / {
    deny all;
}
```


*yanopaste*

```
location ~ ^/(index\.php)??$ {
    allow all;
    fastcgi_pass    local_php;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

location ~ ^.*\.(css|png|jpg|ico|gif|js|html??)$ {
    allow all;
}

location / {
    deny all;
}
```


*dokuwiki*

```
location = /install.php {
    deny all;
}

location ~ ^/(conf|data)/ {
    deny all;
}

location / {
    if (-f $request_filename) {
        expires 3d;
        add_header    Cache-Control  public;
        break;
    }

    if (!-f $request_filename) {
        rewrite ^/(.*)?(.*)  /doku.php?id=$1&$2 last;
        rewrite ^/$ /doku.php last;
        break;
    }
}

rewrite ^/_media/(.*) /lib/exe/fetch.php?media=$1 last;
rewrite ^/_detail/(.*) /lib/exe/detail.php?media=$1 last;
rewrite ^/_export/([^/]+)/(.*) /doku.php?do=export_$1&id=$2 last;

location ~ \.php {
    allow all;
    fastcgi_pass    local_php;
    fastcgi_index  doku.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

location ~* \.(png|gif|jpg|css|js|html)$ {
    allow all;
}

location ~ ^/(\.htaccess\.dist|COPYING|README|VERSION)$ {
    deny all;
}
```


----------



## bes (Sep 24, 2011)

Thanks.
BTW,OpenBSD imports nginx into tree as future apache replacement.
http://marc.info/?l=openbsd-cvs&m=131673440721777&w=2


----------

